Class: EPUB::Publication::Package::Metadata

Inherits:
Object
  • Object
show all
Includes:
Inspector::PublicationModel
Defined in:
lib/epub/publication/package/metadata.rb

Defined Under Namespace

Modules: Refinee Classes: DCMES, Identifier, Link, Meta, Title

Constant Summary collapse

DC_ELEMS =
[:identifiers, :titles, :languages] +
                   [:contributors, :coverages, :creators, :dates, :descriptions, :formats, :publishers,
:relations, :rights, :sources, :subjects, :types]

Constants included from Inspector::PublicationModel

Inspector::PublicationModel::TEMPLATE

Instance Method Summary collapse

Methods included from Inspector::PublicationModel

included, #inspect

Constructor Details

#initializeMetadata

Returns a new instance of Metadata.


19
20
21
22
23
# File 'lib/epub/publication/package/metadata.rb', line 19

def initialize
  (DC_ELEMS + [:metas, :links]).each do |elem|
    __send__ "#{elem}=", []
  end
end

Instance Method Details

#dateObject


47
48
49
# File 'lib/epub/publication/package/metadata.rb', line 47

def date
  dates.first
end

#descriptionObject


43
44
45
# File 'lib/epub/publication/package/metadata.rb', line 43

def description
  descriptions.join(' ')
end

#languageObject


51
52
53
# File 'lib/epub/publication/package/metadata.rb', line 51

def language
  languages.first
end

#primary_metasObject


62
63
64
# File 'lib/epub/publication/package/metadata.rb', line 62

def primary_metas
  metas.select {|meta| meta.primary_expression?}
end

#subtitleObject


39
40
41
# File 'lib/epub/publication/package/metadata.rb', line 39

def subtitle
  titles.select {|title| title.title_type.to_s == 'subtitle'}.sort.join(' ')
end

#titleObject


25
26
27
28
29
30
31
# File 'lib/epub/publication/package/metadata.rb', line 25

def title
  return extended_title unless extended_title.empty?
  compositted = titles.select {|title| title.display_seq}.sort.join("\n")
  return compositted unless compositted.empty?
  return main_title unless main_title.empty?
  titles.sort.join("\n")
end

#to_hObject


55
56
57
58
59
60
# File 'lib/epub/publication/package/metadata.rb', line 55

def to_h
  DC_ELEMS.inject({}) do |hsh, elem|
    hsh[elem] = __send__(elem)
    hsh
  end
end