Class: EPUB::Publication::Package::Metadata
- Inherits:
-
Object
- Object
- EPUB::Publication::Package::Metadata
- Includes:
- ContentModel
- Defined in:
- lib/epub/maker/publication.rb
Defined Under Namespace
Classes: Meta
Instance Method Summary collapse
-
#creator=(name) ⇒ Object
Shortcut to set one creator from String.
-
#language=(lang_code) ⇒ Object
Shortcut to set language from String.
- #make {|_self| ... } ⇒ Object
-
#title=(title) ⇒ Object
Shortcut to set title from String.
- #to_xml_fragment(xml) ⇒ Object
Methods included from ContentModel
Instance Method Details
#creator=(name) ⇒ Object
Shortcut to set one creator from String
179 180 181 182 183 184 |
# File 'lib/epub/maker/publication.rb', line 179 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
170 171 172 173 174 175 |
# File 'lib/epub/maker/publication.rb', line 170 def language=(lang_code) lang = DCMES.new lang.content = lang_code self.dc_languages = [lang] lang_code end |
#make {|_self| ... } ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/epub/maker/publication.rb', line 101 def make yield self if block_given? unless unique_identifier if identifiers.empty? identifier = DCMES.new identifier.id = 'pub-id' identifier.content = SecureRandom.uuid self.dc_identifiers << identifier self.unique_identifier = identifier else self.unique_identifier = identifiers.first end end unless .any? {|| .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. << modified end self end |
#title=(title) ⇒ Object
Shortcut to set title from String
161 162 163 164 165 166 |
# File 'lib/epub/maker/publication.rb', line 161 def title=(title) t = Title.new t.content = title self.dc_titles = [t] title end |
#to_xml_fragment(xml) ⇒ Object
126 127 128 129 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 |
# File 'lib/epub/maker/publication.rb', line 126 def to_xml_fragment(xml) xml.('xmlns:dc' => EPUB::NAMESPACES['dc']) { (DC_ELEMS - [:languages]).each do |elems| singular = elems[0..-2] singular += 's' if elems == :rights singular += '_' __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 .each do || next unless .valid? # TODO: Consider whther to drop or keep as is node = xml.(.content) to_xml_attribute node, , [:property, :id, :scheme] node['refines'] = "##{.refines.id}" if .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 |