Class: EPUB::Metadata

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

Defined Under Namespace

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspector::PublicationModel

included, #inspect, #template

Constructor Details

#initializeMetadata

Returns a new instance of Metadata.



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

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

Instance Attribute Details

#childrenObject (readonly)

Used for CFI



11
12
13
# File 'lib/epub/metadata.rb', line 11

def children
  @children
end

Instance Method Details

#dateObject



53
54
55
# File 'lib/epub/metadata.rb', line 53

def date
  dates.first
end

#descriptionObject



49
50
51
# File 'lib/epub/metadata.rb', line 49

def description
  descriptions.join(' ')
end

#languageObject



57
58
59
# File 'lib/epub/metadata.rb', line 57

def language
  languages.first
end

#modifiedObject



61
62
63
64
65
66
# File 'lib/epub/metadata.rb', line 61

def modified
  metas.find {|meta|
    meta.property == 'dcterms:modified' &&
      meta.refiners.empty?
  }
end

#primary_metasObject



75
76
77
# File 'lib/epub/metadata.rb', line 75

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

#release_identifierObject Also known as: package_identifier



26
27
28
# File 'lib/epub/metadata.rb', line 26

def release_identifier
  "#{unique_identifier}@#{modified}"
end

#subtitleObject



45
46
47
# File 'lib/epub/metadata.rb', line 45

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

#titleObject



31
32
33
34
35
36
37
# File 'lib/epub/metadata.rb', line 31

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



68
69
70
71
72
73
# File 'lib/epub/metadata.rb', line 68

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