class Athena::Formats::Midos

Constants

FIELD_SEPARATOR
RECORD_SEPARATOR
TO_LATIN1
VALUE_SEPARATOR

Attributes

dbm_parser[R]

Public Instance Methods

convert(record) click to toggle source
    # File lib/athena/formats/dbm.rb
 78 def convert(record)
 79   rs, fs, vs, crlf_re, iconv =
 80     RECORD_SEPARATOR, FIELD_SEPARATOR, VALUE_SEPARATOR, CRLF_RE, TO_LATIN1
 81 
 82   dbm = ["ID#{fs}#{record.id}"]
 83 
 84   record.struct.each { |field, struct|
 85     struct_values = struct[:values]
 86     struct_values.default = []
 87 
 88     strings = struct[:elements].map { |element|
 89       values = []
 90 
 91       struct_values[element].each { |value|
 92         if value
 93           value = value.strip.gsub(crlf_re, ' ')
 94           values << value unless value.empty?
 95         end
 96       }
 97 
 98       values.empty? ? struct[:empty] : values.join(vs)
 99     }
100 
101     dbm << "#{field.to_s.upcase}#{fs}#{iconv.iconv(struct[:string] % strings)}"
102   }
103 
104   dbm << rs << CRLF
105 
106   dbm.join(CRLF)
107 end
parse(input, &block) click to toggle source
   # File lib/athena/formats/dbm.rb
60 def parse(input, &block)
61   num = 0
62 
63   dbm_parser.parse(input) { |id, doc|
64     Athena::Record.new(id, block) { |record|
65       config.each { |element, field_config|
66         Array(doc[element]).each { |value|
67           record.update(element, value, field_config)
68         }
69       }
70     }
71 
72     num += 1
73   }
74 
75   num
76 end

Private Instance Methods

init_in(*) click to toggle source
Calls superclass method Athena::Formats::Base#init_in
    # File lib/athena/formats/dbm.rb
111 def init_in(*)
112   @__record_element_ok__ = [String, nil]
113   super
114   @dbm_parser = Nuggets::Midos::Parser.new(:key => record_element)
115 end