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
-
#modified=(datetime) ⇒ Object
Shortcut to set modified date time.
-
#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
180 181 182 183 184 185 |
# File 'lib/epub/maker/publication.rb', line 180 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
171 172 173 174 175 176 |
# File 'lib/epub/maker/publication.rb', line 171 def language=(lang_code) lang = DCMES.new lang.content = lang_code self.dc_languages = [lang] lang_code end |
#make {|_self| ... } ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/epub/maker/publication.rb', line 102 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 |
#modified=(datetime) ⇒ Object
Shortcut to set modified date time
189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/epub/maker/publication.rb', line 189 def modified=(datetime) modified = self.modified unless modified modified = Meta.new modified.property = "dcterms:modified" self. << modified end modified.content = datetime.respond_to?(:to_time) ? datetime.to_time.utc.xmlschema : datetime modified end |
#title=(title) ⇒ Object
Shortcut to set title from String
162 163 164 165 166 167 |
# File 'lib/epub/maker/publication.rb', line 162 def title=(title) t = Title.new t.content = title self.dc_titles = [t] title end |
#to_xml_fragment(xml) ⇒ Object
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 158 |
# File 'lib/epub/maker/publication.rb', line 127 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 |