-
-
Save anonymous/a18432ac8ee48d17aea6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
require 'YAML' | |
class Customers | |
attr_reader :cust_id, :elect_or_gas, :disconnect_doc, :move_in_date, :move_out_date, :bill_year, :bill_month, :span_days, :meter_read_date, :meter_read_type, :consumption, :exception_code | |
def initialize cust_id, elect_or_gas, disconnect_doc, move_in_date, move_out_date, bill_year, bill_month, span_days, meter_read_date, meter_read_type, consumption, exception_code | |
@cust_id = cust_id | |
@elect_or_gas = elect_or_gas | |
@disconnect_doc = disconnect_doc | |
@move_in_date = move_in_date | |
@move_out_date = move_out_date | |
@bill_year = bill_year | |
@bill_month = bill_month | |
@span_days = span_days | |
@meter_read_date = meter_read_date | |
@meter_read_type = meter_read_type | |
@consumption = consumption | |
@exception_code = exception_code | |
end | |
end | |
class Parse | |
attr_accessor :customers | |
def initialize filename | |
customers = [] | |
deserialized_users filename | |
end | |
def deserialized_users filename | |
CSV.foreach(filename, col_sep: "|") do |row| | |
next if row.empty? | |
cust_id, elect_or_gas, disconnect_doc, move_in_date, move_out_date, bill_year, bill_month, span_days, meter_read_date, meter_read_type, consumption, exception_code = row | |
#sanitized_values(cust_id, elect_or_gas, disconnect_doc, move_in_date, move_out_date, bill_year, bill_month, span_days, meter_read_date, meter_read_type, consumption, exception_code = row) | |
customers << Customers.new(cust_id, elect_or_gas, disconnect_doc, move_in_date, move_out_date, bill_year, bill_month, span_days, meter_read_date, meter_read_type, consumption, exception_code) | |
end | |
customers | |
end | |
def serialized_users | |
File.open("./serialized_users.yaml", "w") do |yaml_file| | |
customers.each do |c| | |
yaml_file.puts YAML::dump([c.cust_id, c.elect_or_gas, c.disconnect_doc, c.move_in_date, c.move_out_date, c.bill_year, c.bill_month, c.span_days, c.meter_read_date, c.meter_read_type, c.consumption, c.exception_code]) | |
end | |
end | |
end | |
end | |
p = Parse.new "./pulse_data.txt" | |
#p.serialized_users | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment