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

#modifiedObject



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

def modified
  metas.find {|meta| meta.property == 'dcterms:modified'}
end

#primary_metasObject



66
67
68
# File 'lib/epub/publication/package/metadata.rb', line 66

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



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

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