Module: Cards::TabularParser

Included in:
CsvParser, NumbersParser
Defined in:
lib/cards/tabular_parser.rb

Defined Under Namespace

Classes: Row

Instance Method Summary collapse

Instance Method Details

#denormalized_rows(key_column, columns_to_denormalize) ⇒ Object

this method will turn something of the form

activity | task | story | a | | |

| b       |         |
|         | c       |
|         | d       |

into

activity | task | story | a | b | c | a | b | d |



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cards/tabular_parser.rb', line 34

def denormalized_rows(key_column, columns_to_denormalize)
  last_row = {}
  rows = []
  each_row do |row|
    row = row.to_h
    columns_to_denormalize.each do |c|
      row[c] = last_row[c] if row[c].blank?
    end
    rows << row unless row[key_column].blank?
    last_row = row
  end
  rows
end

#each_rowObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/cards/tabular_parser.rb', line 9

def each_row
  header = nil
  each_unparsed_row do |row|
    if header.nil?
      header = define_header(row)
    else
      yield Row.new(header, row)
    end
  end
end

#rowsObject



3
4
5
6
7
# File 'lib/cards/tabular_parser.rb', line 3

def rows
  rows = []
  each_row {|row| rows << row}
  rows
end