Class: Mabmapper::Engine
- Inherits:
-
Object
- Object
- Mabmapper::Engine
- Defined in:
- lib/mabmapper/engine.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Field
Class Method Summary collapse
Instance Method Summary collapse
- #fields ⇒ Object
- #process(input_filename, contents, options = {archive: nil}) ⇒ Object
- #to_hash ⇒ Object
- #to_xml(only_fields = []) ⇒ Object
Class Method Details
.document_class(value) ⇒ Object
67 68 69 |
# File 'lib/mabmapper/engine.rb', line 67 def document_class(value) self.document_class_value = value end |
Instance Method Details
#fields ⇒ Object
28 29 30 |
# File 'lib/mabmapper/engine.rb', line 28 def fields self.class.fields end |
#process(input_filename, contents, options = {archive: nil}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mabmapper/engine.rb', line 5 def process(input_filename, contents, ={archive: nil}) document_class = self.class.document_class_value raise "The engine does't provide a document class. This is required." unless document_class.present? document = document_class.new(contents) fields.each do |field| begin field.send(:process, document) rescue => e puts "----------------------------" puts "Error : #{e.}" puts "Field : #{field.name}" puts "File : #{input_filename}" puts "Archive: #{[:archive]}" if [:archive].present? puts "----------------------------" puts "Backtrace:" puts e.backtrace puts "----------------------------" puts end end self end |
#to_hash ⇒ Object
55 56 57 58 59 |
# File 'lib/mabmapper/engine.rb', line 55 def to_hash hash = {} fields.each { |field| hash[field.name.downcase] = field.result } hash end |
#to_xml(only_fields = []) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mabmapper/engine.rb', line 32 def to_xml(only_fields = []) builder = Nokogiri::XML::Builder.new do |xml| xml.document do fields.each do |field| if field.result.present? || field.result == false next if only_fields.present? and not only_fields.include?(field.name) if field.result.is_a?(Array) #xml.send("#{field.name.downcase.pluralize}_") do field.result.each do |result| xml.send("#{field.name.downcase}_", result) end #end else xml.send("#{field.name.downcase}_", field.result) end end end end end builder.to_xml end |