Class: WrapExcel::Range

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wrap_excel/range.rb

Instance Method Summary collapse

Constructor Details

#initialize(win32_range) ⇒ Range

Returns a new instance of Range.



6
7
8
# File 'lib/wrap_excel/range.rb', line 6

def initialize(win32_range)
  @range = win32_range
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



26
27
28
# File 'lib/wrap_excel/range.rb', line 26

def method_missing(id, *args)
  @range.send(id, *args)
end

Instance Method Details

#[](index) ⇒ Object



21
22
23
24
# File 'lib/wrap_excel/range.rb', line 21

def [] index
  @cells ||= []
  @cells[index + 1] ||= WrapExcel::Cell.new(@range.Cells.Item(index + 1))
end

#eachObject



10
11
12
13
14
# File 'lib/wrap_excel/range.rb', line 10

def each
  @range.each do |row_or_column|
    yield WrapExcel::Cell.new(row_or_column)
  end
end

#values(range = nil) ⇒ Object



16
17
18
19
# File 'lib/wrap_excel/range.rb', line 16

def values(range = nil)
  result = self.map(&:value).flatten
  range ? result.each_with_index.select{ |row_or_column, i| range.include?(i) }.map{ |i| i[0] } : result
end