Class: AppEarnings::Amazon::Parser
- Inherits:
-
Object
- Object
- AppEarnings::Amazon::Parser
- Defined in:
- lib/app_earnings/amazon/parser.rb
Overview
Converts a csv file to a hash.
Instance Attribute Summary collapse
-
#file_name ⇒ Object
Returns the value of attribute file_name.
Instance Method Summary collapse
- #extract ⇒ Object
-
#initialize(file_name) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(file_name) ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/app_earnings/amazon/parser.rb', line 8 def initialize(file_name) @file_name = file_name @contents = File.read(@file_name) @header, @summary, @details = @contents.split(/Summary|Detail/) if @header =~ /Payment Report/ @report_type = :payments else @report_type = :earnings end end |
Instance Attribute Details
#file_name ⇒ Object
Returns the value of attribute file_name.
6 7 8 |
# File 'lib/app_earnings/amazon/parser.rb', line 6 def file_name @file_name end |
Instance Method Details
#extract ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/app_earnings/amazon/parser.rb', line 20 def extract { report_type: @report_type, header: @header, summary: parse(@summary.strip), details: parse((@details || '').strip) } end |