Class: AssetMapFromFile
- Defined in:
- lib/datashift/mapping_file_definitions.rb
Overview
Expects file of format [TradeType,LDN_TradeId,HUB_TradeId,LDN_AssetId,HUB_AssetId,LDN_StrutureId,HUB_StructureId,LDN_ProductType,HUB_ProductType] Convets in to and araya containing rows [LDN_TradeId, LDN_AssetId, HUB_TradeId, HUB_AssetId]
Instance Method Summary collapse
- #intialize(file_path, delim = ',') ⇒ Object
- #load_map(file_path = nil, delim = ',') ⇒ Object
- #write_map(file_path = nil, delim = ',') ⇒ Object
Instance Method Details
#intialize(file_path, delim = ',') ⇒ Object
57 58 59 60 61 |
# File 'lib/datashift/mapping_file_definitions.rb', line 57 def intialize(file_path, delim = ',') @delegate_to = {} @delim = delim load_map(file_path) end |
#load_map(file_path = nil, delim = ',') ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/datashift/mapping_file_definitions.rb', line 63 def load_map(file_path = nil, delim = ',') @file = file_path unless file_path.nil? @delim = delim raise ArgumentError.new("Can not read asset map file: #{@file}") unless File.readable?(@file) File.open(@file).each_line do |line| next unless(line && line.chomp!) # skip the header row next if line.include?('TradeType') values = line.split(@delim) self.push(Array[values[1], values[3], values[2], values[4]]) end return self end |
#write_map(file_path = nil, delim = ',') ⇒ Object
82 83 84 85 86 |
# File 'lib/datashift/mapping_file_definitions.rb', line 82 def write_map(file_path = nil, delim = ',') mapfile = File.open( file_path, 'w') self.each{|row| mapfile.write(row.join(delim)+"\n")} end |