Class: Epuber::Book::Contributor
- Inherits:
-
Object
- Object
- Epuber::Book::Contributor
- Defined in:
- lib/epuber/book/contributor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_as ⇒ String
readonly
File-as of contributor used in .opf file.
-
#pretty_name ⇒ String
readonly
Pretty name of contributor used in .opf file and copyright page.
-
#role ⇒ String
readonly
Role of contributor.
Class Method Summary collapse
-
.from_obj(obj, role = 'aut') ⇒ Contributor
Creates new instance of Contributor dependent on obj content.
Instance Method Summary collapse
-
#initialize(pretty_name, file_as, role) ⇒ Contributor
constructor
A new instance of Contributor.
Constructor Details
#initialize(pretty_name, file_as, role) ⇒ Contributor
Returns a new instance of Contributor.
26 27 28 29 30 |
# File 'lib/epuber/book/contributor.rb', line 26 def initialize(pretty_name, file_as, role) @file_as = file_as @pretty_name = pretty_name @role = role end |
Instance Attribute Details
#file_as ⇒ String (readonly)
File-as of contributor used in .opf file
9 10 11 |
# File 'lib/epuber/book/contributor.rb', line 9 def file_as @file_as end |
#pretty_name ⇒ String (readonly)
Pretty name of contributor used in .opf file and copyright page
14 15 16 |
# File 'lib/epuber/book/contributor.rb', line 14 def pretty_name @pretty_name end |
#role ⇒ String (readonly)
Role of contributor
19 20 21 |
# File 'lib/epuber/book/contributor.rb', line 19 def role @role end |
Class Method Details
.from_obj(obj, role = 'aut') ⇒ Contributor
Creates new instance of Contributor dependent on obj content
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/epuber/book/contributor.rb', line 39 def self.from_obj(obj, role = 'aut') if obj.is_a?(String) components = obj.split if components.length >= 2 NormalContributor.new(components.first(components.length - 1).join(' '), components.last, role) else Contributor.new(obj, obj, role) end elsif obj.is_a?(Hash) if obj.key?(:first_name) NormalContributor.new(obj[:first_name], obj[:last_name], obj[:role] || role) elsif obj.key?(:file_as) Contributor.new(obj[:pretty_name], obj[:file_as], obj[:role] || role) elsif obj.key?(:name) Contributor.from_obj(obj[:name], obj[:role] || role) end end end |