class Mbrao::Author
Represents the author of a parsed content, with its metadata.
@attribute uid
@return [String] A unique ID for this post. This is only for client uses.
@attribute name
@return [String] The name of the author.
@attribute email
@return [String] The email of the author.
@attribute website
@return [String] The website of the author.
@attribute image
@return [String] The URL of the avatar of the author.
@attribute metadata
@return [HashWithIndifferentAccess] The full list of metadata of this author.
Attributes
email[RW]
image[RW]
metadata[RW]
name[RW]
uid[RW]
website[RW]
Public Class Methods
create(data)
click to toggle source
Creates an author from a `Hash`.
@param data [Hash] The data of the author @return [Author] A new author.
# File lib/mbrao/author.rb, line 62 def self.create(data) if data.is_a?(Hash) data = HashWithIndifferentAccess.new(data) uid = data.delete(:uid) metadata = data.delete(:metadata) || {} author = Mbrao::Author.new(data.delete(:name), data.delete(:email), data.delete(:website), data.delete(:image), metadata.merge(data)) author.uid = uid author else Mbrao::Author.new(data) end end
new(name, email = nil, website = nil, image = nil, metadata = nil)
click to toggle source
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.
# File lib/mbrao/author.rb, line 37 def initialize(name, email = nil, website = nil, image = nil, metadata = 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 = metadata.ensure_hash(accesses: :indifferent) end
Public Instance Methods
as_json(options = {})
click to toggle source
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.
# 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