Class: RubyXL::Address
- Inherits:
-
Object
- Object
- RubyXL::Address
- Defined in:
- lib/rubyXL/address.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #cell ⇒ RubyXL::Cell?
- #column(column = nil) ⇒ Integer, RubyXL::Address
- #column=(column) ⇒ Integer, ...
- #down(amount = 1) ⇒ RubyXL::Address
- #down!(amount = 1) ⇒ self
- #exists? ⇒ Boolean
-
#initialize(worksheet, ref: nil, row: nil, column: nil) ⇒ Address
constructor
A new instance of Address.
- #inspect ⇒ String
- #left(amount = 1) ⇒ RubyXL::Address
- #left!(amount = 1) ⇒ self
- #ref ⇒ String
- #right(amount = 1) ⇒ RubyXL::Address
- #right!(amount = 1) ⇒ self
- #row(row = nil) ⇒ Integer, RubyXL::Address
- #row=(row) ⇒ Integer, ...
- #up(amount = 1) ⇒ RubyXL::Address
- #up!(amount = 1) ⇒ self
- #value ⇒ Object
- #value=(value) ⇒ Object
Constructor Details
#initialize(worksheet, ref: nil, row: nil, column: nil) ⇒ Address
Returns a new instance of Address.
13 14 15 16 17 18 19 |
# File 'lib/rubyXL/address.rb', line 13 def initialize(worksheet, ref: nil, row: nil, column: nil) @worksheet = worksheet row, column = Reference.ref2ind(ref) if ref self.row = row self.column = column end |
Instance Attribute Details
#worksheet(worksheet = nil) ⇒ RubyXL::Workbook, RubyXL::Address
23 24 25 26 27 28 29 |
# File 'lib/rubyXL/address.rb', line 23 def worksheet(worksheet = nil) if worksheet.nil? @worksheet else self.class.new(worksheet, row: @row, column: @column) end end |
Instance Method Details
#cell ⇒ RubyXL::Cell?
126 127 128 |
# File 'lib/rubyXL/address.rb', line 126 def cell (row = @worksheet[@row]) && row[@column] end |
#column(column = nil) ⇒ Integer, RubyXL::Address
43 44 45 46 47 48 49 |
# File 'lib/rubyXL/address.rb', line 43 def column(column = nil) if column.nil? @column else self.class.new(@worksheet, row: @row, column: column) end end |
#column=(column) ⇒ Integer, ...
59 60 61 |
# File 'lib/rubyXL/address.rb', line 59 def column=(column) @column = Addressing.__send__(:normalize, 'column', column) end |
#down(amount = 1) ⇒ RubyXL::Address
81 82 83 |
# File 'lib/rubyXL/address.rb', line 81 def down(amount = 1) row(@row + amount) end |
#down!(amount = 1) ⇒ self
106 107 108 109 |
# File 'lib/rubyXL/address.rb', line 106 def down!(amount = 1) self.row += amount self end |
#exists? ⇒ Boolean
131 132 133 |
# File 'lib/rubyXL/address.rb', line 131 def exists? !cell.nil? end |
#inspect ⇒ String
69 70 71 |
# File 'lib/rubyXL/address.rb', line 69 def inspect format('#<%s %s!%s>', self.class.name, @worksheet.sheet_name, ref) end |
#left(amount = 1) ⇒ RubyXL::Address
87 88 89 |
# File 'lib/rubyXL/address.rb', line 87 def left(amount = 1) column(@column - amount) end |
#left!(amount = 1) ⇒ self
113 114 115 116 |
# File 'lib/rubyXL/address.rb', line 113 def left!(amount = 1) self.column -= amount self end |
#ref ⇒ String
64 65 66 |
# File 'lib/rubyXL/address.rb', line 64 def ref Reference.ind2ref(@row, @column) end |
#right(amount = 1) ⇒ RubyXL::Address
93 94 95 |
# File 'lib/rubyXL/address.rb', line 93 def right(amount = 1) column(@column + amount) end |
#right!(amount = 1) ⇒ self
120 121 122 123 |
# File 'lib/rubyXL/address.rb', line 120 def right!(amount = 1) self.column += amount self end |
#row(row = nil) ⇒ Integer, RubyXL::Address
33 34 35 36 37 38 39 |
# File 'lib/rubyXL/address.rb', line 33 def row(row = nil) if row.nil? @row else self.class.new(@worksheet, row: row, column: @column) end end |
#row=(row) ⇒ Integer, ...
53 54 55 |
# File 'lib/rubyXL/address.rb', line 53 def row=(row) @row = Addressing.__send__(:normalize, 'row', row) end |
#up(amount = 1) ⇒ RubyXL::Address
75 76 77 |
# File 'lib/rubyXL/address.rb', line 75 def up(amount = 1) row(@row - amount) end |
#up!(amount = 1) ⇒ self
99 100 101 102 |
# File 'lib/rubyXL/address.rb', line 99 def up!(amount = 1) self.row -= amount self end |
#value ⇒ Object
136 137 138 |
# File 'lib/rubyXL/address.rb', line 136 def value cell && cell.value end |
#value=(value) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/rubyXL/address.rb', line 142 def value=(value) if cell cell.change_contents(value) else @worksheet.add_cell(@row, @column, value) end end |