Class: CSVParser
- Inherits:
-
Object
- Object
- CSVParser
- Defined in:
- lib/csv_parser.rb
Instance Attribute Summary collapse
-
#client_name ⇒ Object
readonly
Returns the value of attribute client_name.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
-
#yml_path ⇒ Object
readonly
Returns the value of attribute yml_path.
Instance Method Summary collapse
-
#initialize(yml_path, client_name) ⇒ CSVParser
constructor
A new instance of CSVParser.
- #parse(csv_row) ⇒ Object
- #yml ⇒ Object
Constructor Details
#initialize(yml_path, client_name) ⇒ CSVParser
Returns a new instance of CSVParser.
11 12 13 14 15 |
# File 'lib/csv_parser.rb', line 11 def initialize(yml_path, client_name) @yml_path = yml_path @client_name = client_name @table_name = File.basename(yml_path, '.yml') end |
Instance Attribute Details
#client_name ⇒ Object (readonly)
Returns the value of attribute client_name.
9 10 11 |
# File 'lib/csv_parser.rb', line 9 def client_name @client_name end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
9 10 11 |
# File 'lib/csv_parser.rb', line 9 def table_name @table_name end |
#yml_path ⇒ Object (readonly)
Returns the value of attribute yml_path.
9 10 11 |
# File 'lib/csv_parser.rb', line 9 def yml_path @yml_path end |
Instance Method Details
#parse(csv_row) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/csv_parser.rb', line 21 def parse(csv_row) ModuleHelper.deep_transform_values_with_path(mapping_hash) do |csv_field_name, path| field_name = path.last if ModuleHelper.needs_method?(csv_field_name) parsed_signature = ModuleHelper.parse_signature(csv_field_name, client_name, table_name, field_name) args = argument_values(parsed_signature[:arguments], csv_row) module_path = parsed_signature[:path] module_path += path[0..-2] unless ModuleHelper.shared_method?(csv_field_name) call_shared_or_client_method( module_path, parsed_signature[:method_name], *args ) else csv_row[csv_field_name] end end end |
#yml ⇒ Object
17 18 19 |
# File 'lib/csv_parser.rb', line 17 def yml @yml ||= YAML.load_file(yml_path).deep_symbolize_keys end |