Class: Tanemaki::Parser

Inherits:
Object show all
Defined in:
lib/tanemaki.rb

Class Method Summary collapse

Class Method Details

.call(*args) ⇒ Object



29
30
31
# File 'lib/tanemaki.rb', line 29

def call(*args)
  ready(*args)
end

.ready(path) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tanemaki.rb', line 34

def ready(path)
  header, *lines = CSV.read(path)
  nameless = []
  readiness = header.map.with_index do |name, index|
    if name
      name.to_sym
    else
      nameless.push(index)
      nil
    end
  end

  lines.map do |line|
    nameless_parameter = []
    line.each_with_index.each_with_object({}) do |(col, index), result|
      if nameless.include?(index)
        nameless_parameter.push(col) if col
      else
        result[readiness[index]] = col if col
      end
    end.merge(namelass_parameter_array: nameless_parameter)
  end
end