Class: Arx::Author

Inherits:
Object
  • Object
show all
Includes:
Inspector, HappyMapper
Defined in:
lib/arx/entities/author.rb

Overview

Entity/model representing an arXiv paper’s author.

Constant Summary collapse

ATTRIBUTES =

The attributes of an arXiv paper’s author.

%i[name affiliated? affiliations]

Instance Method Summary collapse

Methods included from Inspector

included, #inspect, inspected

Instance Method Details

#==(author) ⇒ Boolean

Note:

This only performs a basic equality check between the authors’ names.

Equality check against another author.

Parameters:

  • author (Author)

    The author to compare against.

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/arx/entities/author.rb', line 58

def ==(author)
  if author.is_a? Author
    name == author.name
  else
    false
  end
end

#affiliated?Boolean

Whether or not the author has any affiliations.

Returns:

  • (Boolean)


28
29
30
# File 'lib/arx/entities/author.rb', line 28

def affiliated?
  !affiliations.empty?
end

#affiliationsArray<String>

The author’s affiliations.

Returns:

  • (Array<String>)


23
# File 'lib/arx/entities/author.rb', line 23

has_many :affiliations, Cleaner, tag: 'affiliation', parser: :clean

#as_jsonHash

Serializes the Arx::Author object into a valid JSON hash.

Returns:

  • (Hash)

    The resulting JSON hash.



42
43
44
# File 'lib/arx/entities/author.rb', line 42

def as_json
  JSON.parse to_json
end

#nameString

The name of the author.

Returns:

  • (String)


17
# File 'lib/arx/entities/author.rb', line 17

element :name, Cleaner, tag: 'name', parser: :clean

#to_hHash

Serializes the Arx::Author object into a Hash.

Returns:

  • (Hash)


35
36
37
# File 'lib/arx/entities/author.rb', line 35

def to_h
  Hash[*ATTRIBUTES.map {|_| [_, send(_)]}.flatten(1)]
end

#to_jsonString

Serializes the Arx::Author object into a valid JSON string.

Returns:

  • (String)

    The resulting JSON string.



49
50
51
# File 'lib/arx/entities/author.rb', line 49

def to_json
  to_h.to_json
end

#to_sString

A string representation of the Arx::Author object.

Returns:

  • (String)


69
70
71
# File 'lib/arx/entities/author.rb', line 69

def to_s
  "Arx::Author(name: #{name}, affiliations: [#{affiliations.join(', ')}])"
end