Class: Mbrao::Author

Inherits:
Object
  • Object
show all
Defined in:
lib/mbrao/author.rb

Overview

Represents the author of a parsed content, with its metadata.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, email = nil, website = nil, image = nil, metadata = nil) ⇒ Author

Creates a new author.



37
38
39
40
41
42
43
# File 'lib/mbrao/author.rb', line 37

def initialize(name, email = nil, website = nil, image = nil,  = nil)
  @name = name.ensure_string
  @email = Mbrao::Parser.email?(email) ? email : nil
  @website = Mbrao::Parser.url?(website) ? website : nil
  @image = Mbrao::Parser.url?(image) ? image : nil
  @metadata = .ensure_hash(accesses: :indifferent)
end

Instance Attribute Details

#emailString



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mbrao/author.rb', line 22

class Author
  attr_accessor :uid
  attr_accessor :name
  attr_accessor :email
  attr_accessor :website
  attr_accessor :image
  attr_accessor :metadata

  # Creates a new author.
  #
  # @param name [String] The name of the author.
  # @param email [String] The email of the author.
  # @param website [String] The website of the author.
  # @param image [String] The URL of the avatar of the author.
  # @param metadata [HashWithIndifferentAccess] The full list of metadata of this author.
  def initialize(name, email = nil, website = nil, image = nil,  = nil)
    @name = name.ensure_string
    @email = Mbrao::Parser.email?(email) ? email : nil
    @website = Mbrao::Parser.url?(website) ? website : nil
    @image = Mbrao::Parser.url?(image) ? image : nil
    @metadata = .ensure_hash(accesses: :indifferent)
  end

  # Returns the author as an Hash.
  #
  # @param options [Hash] Options to modify behavior of the serialization.
  #   The only supported value are:
  #
  #   * `:exclude`, an array of attributes to skip.
  #   * `:exclude_empty`, if to exclude nil values. Default is `false`.
  # @return [Hash] An hash with all attributes.
  def as_json(options = {})
    keys = [:uid, :name, :email, :website, :image, :metadata]
    ::Mbrao::Parser.as_json(self, keys, options)
  end

  # Creates an author from a `Hash`.
  #
  # @param data [Hash] The data of the author
  # @return [Author] A new author.
  def self.create(data)
    if data.is_a?(Hash)
      data = HashWithIndifferentAccess.new(data)
      uid = data.delete(:uid)
       = data.delete(:metadata) || {}
      author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), .merge(data))
      author.uid = uid
      author
    else
      Mbrao::Author.new(data)
    end
  end
end

#imageString



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mbrao/author.rb', line 22

class Author
  attr_accessor :uid
  attr_accessor :name
  attr_accessor :email
  attr_accessor :website
  attr_accessor :image
  attr_accessor :metadata

  # Creates a new author.
  #
  # @param name [String] The name of the author.
  # @param email [String] The email of the author.
  # @param website [String] The website of the author.
  # @param image [String] The URL of the avatar of the author.
  # @param metadata [HashWithIndifferentAccess] The full list of metadata of this author.
  def initialize(name, email = nil, website = nil, image = nil,  = nil)
    @name = name.ensure_string
    @email = Mbrao::Parser.email?(email) ? email : nil
    @website = Mbrao::Parser.url?(website) ? website : nil
    @image = Mbrao::Parser.url?(image) ? image : nil
    @metadata = .ensure_hash(accesses: :indifferent)
  end

  # Returns the author as an Hash.
  #
  # @param options [Hash] Options to modify behavior of the serialization.
  #   The only supported value are:
  #
  #   * `:exclude`, an array of attributes to skip.
  #   * `:exclude_empty`, if to exclude nil values. Default is `false`.
  # @return [Hash] An hash with all attributes.
  def as_json(options = {})
    keys = [:uid, :name, :email, :website, :image, :metadata]
    ::Mbrao::Parser.as_json(self, keys, options)
  end

  # Creates an author from a `Hash`.
  #
  # @param data [Hash] The data of the author
  # @return [Author] A new author.
  def self.create(data)
    if data.is_a?(Hash)
      data = HashWithIndifferentAccess.new(data)
      uid = data.delete(:uid)
       = data.delete(:metadata) || {}
      author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), .merge(data))
      author.uid = uid
      author
    else
      Mbrao::Author.new(data)
    end
  end
end

#metadataHashWithIndifferentAccess



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mbrao/author.rb', line 22

class Author
  attr_accessor :uid
  attr_accessor :name
  attr_accessor :email
  attr_accessor :website
  attr_accessor :image
  attr_accessor :metadata

  # Creates a new author.
  #
  # @param name [String] The name of the author.
  # @param email [String] The email of the author.
  # @param website [String] The website of the author.
  # @param image [String] The URL of the avatar of the author.
  # @param metadata [HashWithIndifferentAccess] The full list of metadata of this author.
  def initialize(name, email = nil, website = nil, image = nil,  = nil)
    @name = name.ensure_string
    @email = Mbrao::Parser.email?(email) ? email : nil
    @website = Mbrao::Parser.url?(website) ? website : nil
    @image = Mbrao::Parser.url?(image) ? image : nil
    @metadata = .ensure_hash(accesses: :indifferent)
  end

  # Returns the author as an Hash.
  #
  # @param options [Hash] Options to modify behavior of the serialization.
  #   The only supported value are:
  #
  #   * `:exclude`, an array of attributes to skip.
  #   * `:exclude_empty`, if to exclude nil values. Default is `false`.
  # @return [Hash] An hash with all attributes.
  def as_json(options = {})
    keys = [:uid, :name, :email, :website, :image, :metadata]
    ::Mbrao::Parser.as_json(self, keys, options)
  end

  # Creates an author from a `Hash`.
  #
  # @param data [Hash] The data of the author
  # @return [Author] A new author.
  def self.create(data)
    if data.is_a?(Hash)
      data = HashWithIndifferentAccess.new(data)
      uid = data.delete(:uid)
       = data.delete(:metadata) || {}
      author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), .merge(data))
      author.uid = uid
      author
    else
      Mbrao::Author.new(data)
    end
  end
end

#nameString



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mbrao/author.rb', line 22

class Author
  attr_accessor :uid
  attr_accessor :name
  attr_accessor :email
  attr_accessor :website
  attr_accessor :image
  attr_accessor :metadata

  # Creates a new author.
  #
  # @param name [String] The name of the author.
  # @param email [String] The email of the author.
  # @param website [String] The website of the author.
  # @param image [String] The URL of the avatar of the author.
  # @param metadata [HashWithIndifferentAccess] The full list of metadata of this author.
  def initialize(name, email = nil, website = nil, image = nil,  = nil)
    @name = name.ensure_string
    @email = Mbrao::Parser.email?(email) ? email : nil
    @website = Mbrao::Parser.url?(website) ? website : nil
    @image = Mbrao::Parser.url?(image) ? image : nil
    @metadata = .ensure_hash(accesses: :indifferent)
  end

  # Returns the author as an Hash.
  #
  # @param options [Hash] Options to modify behavior of the serialization.
  #   The only supported value are:
  #
  #   * `:exclude`, an array of attributes to skip.
  #   * `:exclude_empty`, if to exclude nil values. Default is `false`.
  # @return [Hash] An hash with all attributes.
  def as_json(options = {})
    keys = [:uid, :name, :email, :website, :image, :metadata]
    ::Mbrao::Parser.as_json(self, keys, options)
  end

  # Creates an author from a `Hash`.
  #
  # @param data [Hash] The data of the author
  # @return [Author] A new author.
  def self.create(data)
    if data.is_a?(Hash)
      data = HashWithIndifferentAccess.new(data)
      uid = data.delete(:uid)
       = data.delete(:metadata) || {}
      author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), .merge(data))
      author.uid = uid
      author
    else
      Mbrao::Author.new(data)
    end
  end
end

#uidString



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mbrao/author.rb', line 22

class Author
  attr_accessor :uid
  attr_accessor :name
  attr_accessor :email
  attr_accessor :website
  attr_accessor :image
  attr_accessor :metadata

  # Creates a new author.
  #
  # @param name [String] The name of the author.
  # @param email [String] The email of the author.
  # @param website [String] The website of the author.
  # @param image [String] The URL of the avatar of the author.
  # @param metadata [HashWithIndifferentAccess] The full list of metadata of this author.
  def initialize(name, email = nil, website = nil, image = nil,  = nil)
    @name = name.ensure_string
    @email = Mbrao::Parser.email?(email) ? email : nil
    @website = Mbrao::Parser.url?(website) ? website : nil
    @image = Mbrao::Parser.url?(image) ? image : nil
    @metadata = .ensure_hash(accesses: :indifferent)
  end

  # Returns the author as an Hash.
  #
  # @param options [Hash] Options to modify behavior of the serialization.
  #   The only supported value are:
  #
  #   * `:exclude`, an array of attributes to skip.
  #   * `:exclude_empty`, if to exclude nil values. Default is `false`.
  # @return [Hash] An hash with all attributes.
  def as_json(options = {})
    keys = [:uid, :name, :email, :website, :image, :metadata]
    ::Mbrao::Parser.as_json(self, keys, options)
  end

  # Creates an author from a `Hash`.
  #
  # @param data [Hash] The data of the author
  # @return [Author] A new author.
  def self.create(data)
    if data.is_a?(Hash)
      data = HashWithIndifferentAccess.new(data)
      uid = data.delete(:uid)
       = data.delete(:metadata) || {}
      author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), .merge(data))
      author.uid = uid
      author
    else
      Mbrao::Author.new(data)
    end
  end
end

#websiteString



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mbrao/author.rb', line 22

class Author
  attr_accessor :uid
  attr_accessor :name
  attr_accessor :email
  attr_accessor :website
  attr_accessor :image
  attr_accessor :metadata

  # Creates a new author.
  #
  # @param name [String] The name of the author.
  # @param email [String] The email of the author.
  # @param website [String] The website of the author.
  # @param image [String] The URL of the avatar of the author.
  # @param metadata [HashWithIndifferentAccess] The full list of metadata of this author.
  def initialize(name, email = nil, website = nil, image = nil,  = nil)
    @name = name.ensure_string
    @email = Mbrao::Parser.email?(email) ? email : nil
    @website = Mbrao::Parser.url?(website) ? website : nil
    @image = Mbrao::Parser.url?(image) ? image : nil
    @metadata = .ensure_hash(accesses: :indifferent)
  end

  # Returns the author as an Hash.
  #
  # @param options [Hash] Options to modify behavior of the serialization.
  #   The only supported value are:
  #
  #   * `:exclude`, an array of attributes to skip.
  #   * `:exclude_empty`, if to exclude nil values. Default is `false`.
  # @return [Hash] An hash with all attributes.
  def as_json(options = {})
    keys = [:uid, :name, :email, :website, :image, :metadata]
    ::Mbrao::Parser.as_json(self, keys, options)
  end

  # Creates an author from a `Hash`.
  #
  # @param data [Hash] The data of the author
  # @return [Author] A new author.
  def self.create(data)
    if data.is_a?(Hash)
      data = HashWithIndifferentAccess.new(data)
      uid = data.delete(:uid)
       = data.delete(:metadata) || {}
      author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), .merge(data))
      author.uid = uid
      author
    else
      Mbrao::Author.new(data)
    end
  end
end

Class Method Details

.create(data) ⇒ Author

Creates an author from a Hash.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mbrao/author.rb', line 62

def self.create(data)
  if data.is_a?(Hash)
    data = HashWithIndifferentAccess.new(data)
    uid = data.delete(:uid)
     = data.delete(:metadata) || {}
    author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), .merge(data))
    author.uid = uid
    author
  else
    Mbrao::Author.new(data)
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Hash

Returns the author as an Hash.



53
54
55
56
# File 'lib/mbrao/author.rb', line 53

def as_json(options = {})
  keys = [:uid, :name, :email, :website, :image, :metadata]
  ::Mbrao::Parser.as_json(self, keys, options)
end