class Area

Attributes

excel_finish[R]
excel_start[R]

Public Class Methods

for(text) click to toggle source

This is so that we only have one instance of a given reference specified by its variables

# File src/excel/area.rb, line 12
def Area.for(text)
   @@areas_for_text[text.to_s]
end

Public Instance Methods

calculate_excel_variables() click to toggle source
# File src/excel/area.rb, line 23
def calculate_excel_variables
  if self =~ /([^:]+):(.*)/
    @excel_start = Reference.for($1)
    @excel_finish = Reference.for($2)
  else
    @excel_start = @excel_finish = Reference.for(self)
  end      
  @excel_start.calculate_excel_variables
  @excel_finish.calculate_excel_variables
  self
end
height() click to toggle source
# File src/excel/area.rb, line 54
def height
  calculate_excel_variables
  @excel_finish.excel_row_number -  @excel_start.excel_row_number
end
includes?(reference) click to toggle source
# File src/excel/area.rb, line 87
def includes?(reference)
  calculate_excel_variables
  r = Reference.for(reference)
  r.calculate_excel_variables
  return false if r.excel_row_number < @excel_start.excel_row_number || r.excel_row_number > @excel_finish.excel_row_number
  return false if r.excel_column_number < @excel_start.excel_column_number || r.excel_column_number > @excel_finish.excel_column_number
  true
end
offset(row,column) click to toggle source
# File src/excel/area.rb, line 35
def offset(row,column)
  calculate_excel_variables
  Area.for([
    @excel_start.offset(row,column),
    ':',
    @excel_finish.offset(row,column),
  ].join)
end
offsets() click to toggle source
# File src/excel/area.rb, line 44
def offsets
  Enumerator.new do |yielder|
    0.upto(width).each do |c|
      0.upto(height).each do |r|
        yielder.yield([r,c])
      end
    end
  end
end
to_array_literal(sheet = nil) click to toggle source
# File src/excel/area.rb, line 64
def to_array_literal(sheet = nil)
  calculate_excel_variables
  unfixed_start = @excel_start.unfix
  fc = CachingFormulaParser.instance
  [:array,
    *(0.upto(height).map do |row|
      [:row,
        *(0.upto(width).map do |column|
          if sheet
            fc.sheet_reference(
              [:sheet_reference, sheet, [:cell, unfixed_start.offset(row,column)]]
            )
          else
            [:cell,
              unfixed_start.offset(row,column)
            ]
          end
        end)
      ]
    end)
  ]
end
unfix() click to toggle source
# File src/excel/area.rb, line 18
def unfix
  calculate_excel_variables
  Area.for("#{@excel_start.unfix}:#{@excel_finish.unfix}").calculate_excel_variables
end
width() click to toggle source
# File src/excel/area.rb, line 59
def width
  calculate_excel_variables
  @excel_finish.excel_column_number -  @excel_start.excel_column_number
end