class Gust::Spreadsheet::Structure

Attributes

header_row[R]
inside[R]
object_regions[R]

Public Class Methods

new(header_row) click to toggle source
# File lib/rb-gust/spreadsheet/structure.rb, line 5
def initialize header_row
  @header_row = header_row
  @object_regions = []
  determine_object_structure
end

Private Instance Methods

determine_object_structure() click to toggle source
# File lib/rb-gust/spreadsheet/structure.rb, line 13
def determine_object_structure
  @inside = false
  start_index = 0
  header_row.each_with_index do |cell, i|
    if single_column_object?(i)
      @object_regions << [i,i]
    elsif first_column?(cell)
      start_index = i
      @inside = true
    elsif last_column?(i)
      @object_regions << [start_index, i]
      @inside = false
    end
  end
end
first_column?(cell) click to toggle source
# File lib/rb-gust/spreadsheet/structure.rb, line 33
def first_column?(cell)
  not(inside) && present?(cell)
end
last_column?(i) click to toggle source
# File lib/rb-gust/spreadsheet/structure.rb, line 37
def last_column?(i)
  inside && last_object_heading?(i)
end
last_object_heading?(i) click to toggle source
# File lib/rb-gust/spreadsheet/structure.rb, line 45
def last_object_heading? i
  present?(header_row[i]) && not(present?(header_row[i+1]))
end
present?(cell) click to toggle source
# File lib/rb-gust/spreadsheet/structure.rb, line 41
def present? cell
  cell && cell.length > 0
end
single_column_object?(i) click to toggle source
# File lib/rb-gust/spreadsheet/structure.rb, line 29
def single_column_object? i
  not(inside) && last_object_heading?(i)
end