Class: ISO8583::FileParser
- Inherits:
-
Object
- Object
- ISO8583::FileParser
- Defined in:
- lib/iso8583/file_parser.rb
Constant Summary collapse
- PATH_DEFAULT =
"/shared/bitmap.dat"
Class Method Summary collapse
- .build_klass(mti_format, mti_messages, filepath = PATH_DEFAULT) ⇒ Object
- .create_mti(klass, format, mti_messages) ⇒ Object
- .mount_parameters(data) ⇒ Object
- .parse_file(filepath) ⇒ Object
Class Method Details
.build_klass(mti_format, mti_messages, filepath = PATH_DEFAULT) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/iso8583/file_parser.rb', line 34 def self.build_klass(mti_format, , filepath = PATH_DEFAULT) Class.new(ISO8583::Message) do |klass| klass.include ISO8583 FileParser.create_mti(klass, mti_format, ) FileParser.parse_file(filepath).each do |parameters| klass.bmp(*parameters) end end end |
.create_mti(klass, format, mti_messages) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/iso8583/file_parser.rb', line 14 def self.create_mti(klass, format, ) klass.mti_format(*format) .each do |number, description| klass.mti number, description end end |
.mount_parameters(data) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/iso8583/file_parser.rb', line 6 def self.mount_parameters(data) if data[3].match(/[0-9]/) [data[1].to_i, "", ISO8583.const_get(data[2]), {:length => data[3].to_i}] else [data[1].to_i, "", ISO8583.const_get("#{data[3]}_#{data[2]}")] end end |
.parse_file(filepath) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/iso8583/file_parser.rb', line 21 def self.parse_file(filepath) return [] unless File.exists?(filepath) file = File.open(filepath, "r") file.readlines.inject([]) do |array, line| data = line.match(/([0-9]+)=\"ATT_([a-zA-Z]+);([0-9A-Z]+)/) next(array) unless data array << mount_parameters(data) end ensure file.close if file end |