Module: EBPS::Conversion::ImportModuleSample

Defined in:
lib/ebps/conversion/import_module_sample.rb

Class Method Summary collapse

Class Method Details

.assemble_document(chapters, yaml_value) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/ebps/conversion/import_module_sample.rb', line 76

def self.assemble_document chapters, yaml_value
  doc = Text::Document.new
  doc.title = Conversion::ImportModuleSample.encode(yaml_value['name'])
  chapters.each do |name|
    if chapter = yaml_value[name]
      doc.add_chapter chapter
    end
  end
  doc
end

.encode(txt) ⇒ Object



86
87
88
89
# File 'lib/ebps/conversion/import_module_sample.rb', line 86

def self.encode txt
  txt.force_encoding 'UTF-8'
  txt
end

.import(string_or_io, path = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/ebps/conversion/import_module_sample.rb', line 66

def self.import string_or_io, path=nil
  collection = {}
  YAML.each_document string_or_io do |doc|
    if doc
      collection.store Digest::MD5.hexdigest(doc.to_s), doc
    end
  end
  ## apparently we have some nil-values here (?)
  collection.values.compact
end