class RubyExcel::Element

A Range or Cell in a Sheet

Attributes

address[R]

The address

column[R]

The first Column id in the address

data[R]

The Data underlying the Sheet

parent[R]

The parent Sheet

row[R]

The first Row id in the address

sheet[R]

The parent Sheet

Public Class Methods

new( sheet, addr ) click to toggle source

Creates a RubyExcel::Element instance

@param [RubyExcel::Sheet] sheet the parent Sheet @param [String] addr the address to reference

# File lib/rubyexcel/element.rb, line 34
def initialize( sheet, addr )
  @sheet = sheet
  @data = sheet.data
  @address = addr
  @column = ( addr =~ /[a-z]/i ? column_id( addr ) : 'A' )
  @row = ( addr =~ /\d/ ? row_id( addr ) : 1 )
end

Public Instance Methods

delete() click to toggle source

Delete the data referenced by self.address

# File lib/rubyexcel/element.rb, line 46
def delete
  data.delete( self ); self
end
each() { |data| ... } click to toggle source

Yields each value in the data referenced by the address

# File lib/rubyexcel/element.rb, line 54
def each
  return to_enum( :each ) unless block_given?
  expand( address ).flatten.each { |addr| yield data[ addr ] }
end
each_cell() { |cell| ... } click to toggle source

Yields each Element referenced by the address

# File lib/rubyexcel/element.rb, line 63
def each_cell
  return to_enum( :each_cell ) unless block_given?
  expand( address ).flatten.each { |addr| yield Cell.new( sheet, addr ) }
end
empty?() click to toggle source

Checks whether the data referenced by the address is empty

# File lib/rubyexcel/element.rb, line 72
def empty?
  all? { |v| v.to_s.empty? }
end
first_cell() click to toggle source

Return the first cell in the Range

@return [RubyExcel::Cell]

# File lib/rubyexcel/element.rb, line 82
def first_cell
  Cell.new( sheet, expand( address ).flatten.first )
end
inspect() click to toggle source

View the object for debugging

# File lib/rubyexcel/element.rb, line 90
def inspect
  "#{ self.class }:0x#{ '%x' % ( object_id << 1 ) }: '#{ address }'"
end
last_cell() click to toggle source

Return the last cell in the Range

@return [RubyExcel::Cell]

# File lib/rubyexcel/element.rb, line 100
def last_cell
  Cell.new( sheet, expand( address ).flatten.last )
end
map!() { |data| ... } click to toggle source

Replaces each value with the result of the block

# File lib/rubyexcel/element.rb, line 108
def map!
  return to_enum( :map! ) unless block_given?
  expand( address ).flatten.each { |addr| data[ addr ] = yield data[ addr ] }
end