Class: Epuber::Book::Contributor

Inherits:
Object
  • Object
show all
Defined in:
lib/epuber/book/contributor.rb

Direct Known Subclasses

NormalContributor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pretty_name, file_as, role) ⇒ Contributor

Returns a new instance of Contributor.

Parameters:

  • pretty_name (String)

    pretty name of contributor

  • file_as (String)

    file as of contributor

  • role (String)

    contributor role



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_asString (readonly)

File-as of contributor used in .opf file

Returns:

  • (String)

    pretty name



9
10
11
# File 'lib/epuber/book/contributor.rb', line 9

def file_as
  @file_as
end

#pretty_nameString (readonly)

Pretty name of contributor used in .opf file and copyright page

Returns:

  • (String)

    pretty name



14
15
16
# File 'lib/epuber/book/contributor.rb', line 14

def pretty_name
  @pretty_name
end

#roleString (readonly)

Role of contributor

Returns:

  • (String)

    role



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

Parameters:

  • Hash<Symbol, (Hash<Symbol, String>, Array<Hash<Symbol,String>, String, Array<String>] obj input object)

    String>, Array<Hash<Symbol,String>, String, Array<String>] obj input object

  • role (String) (defaults to: 'aut')

    role of contributor

Returns:



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