Class: FirebaseStats::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/reader.rb

Overview

Parses the Firebase CSV file into sections

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReader

Returns a new instance of Reader.



10
11
12
13
# File 'lib/reader.rb', line 10

def initialize
  super
  @data = {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/reader.rb', line 8

def data
  @data
end

Instance Method Details

#parse(input) ⇒ Object

Parameters:

  • input (Array<String>)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/reader.rb', line 22

def parse(input)
  curr_lines = []
  input.each_with_index do |line, idx|
    curr_lines.append(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

Parameters:

  • filename (String)


16
17
18
19
# File 'lib/reader.rb', line 16

def parse_file(filename)
  lines = File.readlines(filename)
  parse(lines)
end