Module: EBPS::Conversion::FachinfoYaml

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

Class Method Summary collapse

Class Method Details

.assemble_document(chapters, yaml_value) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/ebps/conversion/fachinfo_yaml.rb', line 131

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

.encode(txt) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/ebps/conversion/fachinfo_yaml.rb', line 141

def self.encode txt
  if !txt.is_a?(String) and txt.respond_to?(:to_s)
    txt = txt.to_s
  end
  txt.force_encoding 'UTF-8'
  txt
end

.import(string_or_io, path = nil) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/ebps/conversion/fachinfo_yaml.rb', line 121

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