Class: FirebaseStats::Reader
- Inherits:
-
Object
- Object
- FirebaseStats::Reader
- Defined in:
- lib/reader.rb
Overview
Parses the Firebase CSV file into sections
Class Method Summary collapse
- .mappings ⇒ Object
-
.search_string(section) ⇒ Object
Get the string that is used to find a given section in the CSV.
Instance Method Summary collapse
- #get(section) ⇒ Object
-
#initialize ⇒ Reader
constructor
A new instance of Reader.
- #num_sections ⇒ Object
- #parse(input) ⇒ Object
- #parse_file(filename) ⇒ Object
Constructor Details
#initialize ⇒ Reader
Returns a new instance of Reader.
8 9 10 11 |
# File 'lib/reader.rb', line 8 def initialize super @data = {} end |
Class Method Details
.mappings ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/reader.rb', line 50 def self.mappings { 'Day,28-Day,7-Day,1-Day' => :active_users, 'Day,Average engagement time' => :daily_engagement, 'Page path and screen class,User engagement,Screen views' => :screens, 'Day,Total revenue' => :revenue, 'App,Crash-free users' => :crash_free_users, 'App,Version,Status' => :version_adoption, 'Source,first_open conversions,LTV' => :acquisition, 'Date,Week 0,Week 1,Week 2,Week 3,Week 4,Week 5' => :retention_cohorts, 'Country ID,Sessions,% Total' => :audience_country, 'Device model,Users' => :devices, 'OS with version,Users' => :os_version, 'Gender,Users' => :gender, 'Platform,Users' => :platform, 'Platform,Users,% Total,User engagement,Total revenue' => :platform_engagement } end |
.search_string(section) ⇒ Object
Get the string that is used to find a given section in the CSV
44 45 46 47 48 |
# File 'lib/reader.rb', line 44 def self.search_string(section) header = Reader.mappings.key(section) header = "Category,Male,Other,Female" if header.nil? and section == :gender_age return header end |
Instance Method Details
#get(section) ⇒ Object
17 18 19 20 21 |
# File 'lib/reader.rb', line 17 def get(section) found = @data[section] raise SectionNotFoundError.new(section) if found.nil? found end |
#num_sections ⇒ Object
13 14 15 |
# File 'lib/reader.rb', line 13 def num_sections @data.length end |
#parse(input) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/reader.rb', line 30 def parse(input) @data = {} curr_lines = [] input.each_with_index do |line, idx| curr_lines.push(line) unless comment?(line) || line.strip.empty? if (idx == input.length - 1) || line.strip.empty? process_lines curr_lines unless curr_lines.empty? curr_lines = [] end end end |
#parse_file(filename) ⇒ Object
24 25 26 27 |
# File 'lib/reader.rb', line 24 def parse_file(filename) lines = File.readlines(filename) parse(lines) end |