Class: RubyExcel::Element
- Inherits:
-
Object
- Object
- RubyExcel::Element
- Includes:
- Enumerable, Address
- Defined in:
- lib/rubyexcel/element.rb
Overview
A Range or Cell in a Sheet
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
The address.
-
#column ⇒ Object
readonly
The first Column id in the address.
-
#data ⇒ Object
readonly
The Data underlying the Sheet.
-
#row ⇒ Object
readonly
The first Row id in the address.
-
#sheet ⇒ Object
(also: #parent)
readonly
The parent Sheet.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete the data referenced by self.address.
-
#each ⇒ Object
Yields each value in the data referenced by the address.
-
#each_cell ⇒ Object
Yields each Element referenced by the address.
-
#empty? ⇒ Boolean
Checks whether the data referenced by the address is empty.
-
#first_cell ⇒ RubyExcel::Cell
Return the first cell in the Range.
-
#initialize(sheet, addr) ⇒ Element
constructor
Creates a RubyExcel::Element instance.
-
#inspect ⇒ Object
View the object for debugging.
-
#last_cell ⇒ RubyExcel::Cell
Return the last cell in the Range.
-
#map! ⇒ Object
Replaces each value with the result of the block.
Methods included from Address
#address_to_col_index, #address_to_indices, #col_index, #col_letter, #column_id, #expand, #indices_to_address, #multi_array?, #offset, #row_id, #step_index, #to_range_address
Constructor Details
#initialize(sheet, addr) ⇒ Element
Creates a RubyExcel::Element instance
34 35 36 37 38 39 40 |
# 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 |
Instance Attribute Details
#address ⇒ Object (readonly)
The address
16 17 18 |
# File 'lib/rubyexcel/element.rb', line 16 def address @address end |
#column ⇒ Object (readonly)
The first Column id in the address
22 23 24 |
# File 'lib/rubyexcel/element.rb', line 22 def column @column end |
#data ⇒ Object (readonly)
The Data underlying the Sheet
19 20 21 |
# File 'lib/rubyexcel/element.rb', line 19 def data @data end |
#row ⇒ Object (readonly)
The first Row id in the address
25 26 27 |
# File 'lib/rubyexcel/element.rb', line 25 def row @row end |
#sheet ⇒ Object (readonly) Also known as: parent
The parent Sheet
12 13 14 |
# File 'lib/rubyexcel/element.rb', line 12 def sheet @sheet end |
Instance Method Details
#delete ⇒ Object
Delete the data referenced by self.address
46 47 48 |
# File 'lib/rubyexcel/element.rb', line 46 def delete data.delete( self ); self end |
#each ⇒ Object
Yields each value in the data referenced by the address
54 55 56 57 |
# File 'lib/rubyexcel/element.rb', line 54 def each return to_enum( :each ) unless block_given? ( address ).flatten.each { |addr| yield data[ addr ] } end |
#each_cell ⇒ Object
Yields each Element referenced by the address
63 64 65 66 |
# File 'lib/rubyexcel/element.rb', line 63 def each_cell return to_enum( :each_cell ) unless block_given? ( address ).flatten.each { |addr| yield Cell.new( sheet, addr ) } end |
#empty? ⇒ Boolean
Checks whether the data referenced by the address is empty
72 73 74 |
# File 'lib/rubyexcel/element.rb', line 72 def empty? all? { |v| v.to_s.empty? } end |
#first_cell ⇒ RubyExcel::Cell
Return the first cell in the Range
82 83 84 |
# File 'lib/rubyexcel/element.rb', line 82 def first_cell Cell.new( sheet, ( address ).flatten.first ) end |
#inspect ⇒ Object
View the object for debugging
90 91 92 |
# File 'lib/rubyexcel/element.rb', line 90 def inspect "#{ self.class }:0x#{ '%x' % ( object_id << 1 ) }: '#{ address }'" end |
#last_cell ⇒ RubyExcel::Cell
Return the last cell in the Range
100 101 102 |
# File 'lib/rubyexcel/element.rb', line 100 def last_cell Cell.new( sheet, ( address ).flatten.last ) end |
#map! ⇒ Object
Replaces each value with the result of the block
108 109 110 111 |
# File 'lib/rubyexcel/element.rb', line 108 def map! return to_enum( :map! ) unless block_given? ( address ).flatten.each { |addr| data[ addr ] = yield data[ addr ] } end |