Class: EpubWorm::Extractors::Metadata
- Inherits:
-
Object
- Object
- EpubWorm::Extractors::Metadata
- Extended by:
- Base
- Defined in:
- lib/epub_worm/extractors/metadata.rb
Constant Summary collapse
- SUBJECT_SEPARATOR =
" -- "
Constants included from Base
Class Method Summary collapse
Methods included from Base
as_xml, element_at, elements_at, extended, ns, ns_entry, open_opf, text_at
Class Method Details
.extract(path) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/epub_worm/extractors/metadata.rb', line 14 def self.extract(path) open_opf(path) do |opf_doc| ::EpubWorm::Metadata.new( title: text_at(opf_doc, "//dc:title"), authors: elements_at(opf_doc, "//dc:creator").map(&:text).map(&:strip).reject(&:empty?), language: text_at(opf_doc, "//dc:language"), publisher: text_at(opf_doc, "//dc:publisher"), description: text_at(opf_doc, "//dc:description"), published_at: text_at(opf_doc, "//dc:date") && Date.parse(text_at(opf_doc, "//dc:date")), subjects: elements_at(opf_doc, "//dc:subject").reduce([]) do |subjects, subject| subjects += subject.text.split(SUBJECT_SEPARATOR).map(&:strip).reject(&:empty?) subjects.uniq end ) end end |