Class: Mapper
- Inherits:
-
Object
- Object
- Mapper
- Defined in:
- lib/ptc_datamapper.rb
Instance Method Summary collapse
- #export_data(exportfile) ⇒ Object
- #export_to_file ⇒ Object
- #format_row(data) ⇒ Object
- #get_cr_row ⇒ Object
- #import_data(importfile) ⇒ Object
- #import_from_file ⇒ Object
- #print_result ⇒ Object
Instance Method Details
#export_data(exportfile) ⇒ Object
36 37 38 39 |
# File 'lib/ptc_datamapper.rb', line 36 def export_data(exportfile) @exportfile = exportfile export_to_file end |
#export_to_file ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/ptc_datamapper.rb', line 70 def export_to_file File.open(@exportfile,'w') do |export| export.puts get_cr_row @persons.each do |p| export.puts format_row(p.na_data) export.puts format_row(p.ptc_data) if p.ptc end end end |
#format_row(data) ⇒ Object
56 57 58 59 60 |
# File 'lib/ptc_datamapper.rb', line 56 def format_row(data) row = '' data.each {|r| row = row.to_s + "#{r}|"} row = row[0..-2] end |
#get_cr_row ⇒ Object
52 53 54 |
# File 'lib/ptc_datamapper.rb', line 52 def get_cr_row 'CR|6|9999000024542||9289560|CLEARBNS|||7020||||||20120530||1325|||||||||' end |
#import_data(importfile) ⇒ Object
31 32 33 34 |
# File 'lib/ptc_datamapper.rb', line 31 def import_data(importfile) @importfile = importfile @persons = import_from_file end |
#import_from_file ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ptc_datamapper.rb', line 41 def import_from_file results = import(@importfile) do map_to Person # after_row lambda{|row, person| person.save} start_at_row 0 [input_id, first_name, last_name, address, city, state, zip, email, birth_month, birth_day, birth_year, ptc, date_created] end results end |
#print_result ⇒ Object
62 63 64 65 66 |
# File 'lib/ptc_datamapper.rb', line 62 def print_result @persons.each do |p| puts format_row(p.ptc_data) end end |