Sha256: 6de3f93178f0f8f96c49b1b391f8b764a11836c1eef5beea72ef2e24ba99b698
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
module Arx # Entity/model representing an arXiv paper's author. class Author include HappyMapper include Inspector # The attributes of an arXiv paper's author. ATTRIBUTES = %i[name affiliated? affiliations] tag 'author' # @!method name # The name of the author. # # @return [String] element :name, Cleaner, tag: 'name', parser: :clean # @!method affiliations # The author's affiliations. # # @return [Array<String>] has_many :affiliations, Cleaner, tag: 'affiliation', parser: :clean # Whether or not the author has any affiliations. # # @return [Boolean] def affiliated? !affiliations.empty? end # Serializes the {Author} object into a +Hash+. # # @return [Hash] def to_h Hash[*ATTRIBUTES.map {|_| [_, send(_)]}.flatten(1)] end # Serializes the {Author} object into a valid JSON hash. # # @return [Hash] The resulting JSON hash. def as_json JSON.parse to_json end # Serializes the {Author} object into a valid JSON string. # # @return [String] The resulting JSON string. def to_json to_h.to_json end # Equality check against another author. # # @note This only performs a basic equality check between the authors' names. # @param author [Author] The author to compare against. # @return [Boolean] def ==(author) if author.is_a? Author name == author.name else false end end # A string representation of the {Author} object. # # @return [String] def to_s "Arx::Author(name: #{name}, affiliations: [#{affiliations.join(', ')}])" end inspector *ATTRIBUTES end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arx-1.3.0 | lib/arx/entities/author.rb |