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

Inherits:
Object
  • Object
show all
Includes:
ContentModel
Defined in:
lib/epub/maker/publication.rb

Defined Under Namespace

Classes: Meta

Instance Method Summary collapse

Methods included from ContentModel

#to_xml_attribute

Instance Method Details

#creator=(name) ⇒ Object

Shortcut to set one creator from String

Parameters:

  • name (String)


181
182
183
184
185
186
# File 'lib/epub/maker/publication.rb', line 181

def creator=(name)
  creator = DCMES.new
  creator.content = name
  self.dc_creators = [creator]
  name
end

#language=(lang_code) ⇒ Object

Shortcut to set language from String

Parameters:

  • lang_code (String)


172
173
174
175
176
177
# File 'lib/epub/maker/publication.rb', line 172

def language=(lang_code)
  lang = DCMES.new
  lang.content = lang_code
  self.dc_languages = [lang]
  lang_code
end

#make {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/epub/maker/publication.rb', line 105

def make
  yield self if block_given?
  unless unique_identifier
    if identifiers.empty?
      identifier = DCMES.new
      identifier.id = 'pub-id'
      identifier.content = UUID.create.to_s
      self.dc_identifiers << identifier
      self.unique_identifier = identifier
    else
      self.unique_identifier = identifiers.first
    end
  end

  unless metas.any? {|meta| meta.property == 'dcterms:modified'}
    modified = Meta.new
    modified.property = 'dcterms:modified'
    # modified.content = Time.now.utc.strftime('%FT%TZ')
    modified.content = Time.now.utc.iso8601
    self.metas << modified
  end

  self
end

#title=(title) ⇒ Object

Shortcut to set title from String

Parameters:

  • title (String)


163
164
165
166
167
168
# File 'lib/epub/maker/publication.rb', line 163

def title=(title)
  t = Title.new
  t.content = title
  self.dc_titles = [t]
  title
end

#to_xml_fragment(xml) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/epub/maker/publication.rb', line 130

def to_xml_fragment(xml)
  xml.('xmlns:dc' => EPUB::NAMESPACES['dc']) {
    (DC_ELEMS - [:languages]).each do |elems|
      singular = elems[0..-2] + '_'
      __send__("dc_#{elems}").each do |elem|
        node = xml['dc'].__send__(singular, elem.content)
        to_xml_attribute node, elem, [:id, :dir]
        node['xml:lang'] = elem.lang if elem.lang
      end
    end

    languages.each do |language|
      xml['dc'].language language.content
    end

    metas.each do |meta|
      next unless meta.valid? # TODO: Consider whther to drop or keep as is
      node = xml.meta(meta.content)
      to_xml_attribute node, meta, [:property, :id, :scheme]
      node['refines'] = "##{meta.refines.id}" if meta.refines
    end

    links.each do |link|
      node = xml.link
      to_xml_attribute node, link, [:href, :id, :media_type]
      node['rel'] = link.rel.to_a.join(' ') if link.rel
      node['refines'] = "##{link.refines.id}" if link.refines
    end
  }
end