Class: CommaSplice::VariableColumnFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/comma_splice/helpers/variable_column_finder.rb

Overview

playid,playtype,genre,timestamp,artist,title,albumtitle,label,prepost,programtype,iswebcast,isrequest

17385098,,,01-27-2019 @ 13:58:00,Niney & Soul Syndicate,So Long Dub,Dub Box Set Vol. 2,Trojan,post,live,y,
17385097,,,01-27-2019 @ 13:57:00,King Tubby,Love Thy Neighbor,Jesus Dread,Blood & Fire,post,live,y,
17385096,,,01-27-2019 @ 13:53:00,King Tubby / The Aggrovators,Declaration Of Dub,Dub From The Roots,Charly,post,live,y,
17385095,,,01-27-2019 @ 13:50:00,Harry Mudie / King Tubby,Dub With A Difference,In Dub Conference Vol. 1,Moodisc,post,live,y,
17385094,,,01-27-2019 @ 13:47:00,KIng Tubby Meets The Upsetter,King And The Upsetter At Spanish Town,KIng Tubby Meets The Upsetter,Celluloid,post,live,y,

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header_line, value_lines, separator = ',') ⇒ VariableColumnFinder

Returns a new instance of VariableColumnFinder.



23
24
25
26
27
28
# File 'lib/comma_splice/helpers/variable_column_finder.rb', line 23

def initialize(header_line, value_lines, separator = ',')
  @values = value_lines
  @header = header_line
  @separator = separator
  find_variable_column_boundaries
end

Instance Attribute Details

#end_columnObject (readonly)

Returns the value of attribute end_column.



21
22
23
# File 'lib/comma_splice/helpers/variable_column_finder.rb', line 21

def end_column
  @end_column
end

#separatorObject (readonly)

Returns the value of attribute separator.



21
22
23
# File 'lib/comma_splice/helpers/variable_column_finder.rb', line 21

def separator
  @separator
end

#start_columnObject (readonly)

Returns the value of attribute start_column.



21
22
23
# File 'lib/comma_splice/helpers/variable_column_finder.rb', line 21

def start_column
  @start_column
end

Instance Method Details

#find_variable_column_boundariesObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/comma_splice/helpers/variable_column_finder.rb', line 30

def find_variable_column_boundaries
  # Now given both of these, we can eliminate some columns on the left and right
  variables = left_to_right_index.zip(right_to_left_index).map do |pair|
    pair == [false, false]
  end

  start_column = variables.find_index(true)
  end_column = variables.reverse.find_index(true)

  @start_column = start_column || 0
  @end_column = (end_column || 1) * -1
end