Class: ExcelAbstraction::ActiveCellReference

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/excel_templating/excel_abstraction/active_cell_reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ ActiveCellReference

Returns a new instance of ActiveCellReference.



7
8
9
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 7

def initialize(attrs = {})
  @position = ExcelAbstraction::CellReference.new(attrs)
end

Instance Attribute Details

#positionObject (protected)

Returns the value of attribute position.



57
58
59
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 57

def position
  @position
end

Instance Method Details

#carriage_returnObject



34
35
36
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 34

def carriage_return
  goto(row, 0)
end

#down(times = 1) ⇒ Object



22
23
24
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 22

def down(times = 1)
  goto(row + times, col)
end

#goto(row, col) ⇒ Object



47
48
49
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 47

def goto(row, col)
  self.position = ExcelAbstraction::CellReference.new(row: row, col: col)
end

#left(times = 1) ⇒ Object



26
27
28
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 26

def left(times = 1)
  goto(row, col - times)
end

#linefeedObject



38
39
40
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 38

def linefeed
  down
end

#move(directions = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 11

def move(directions = {})
  directions.each do |type, times|
    self.respond_to?(type) ? self.__send__(type, times) : raise(ArgumentError.new("Movement direction is not valid."))
  end
  position
end

#newlineObject



42
43
44
45
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 42

def newline
  carriage_return
  linefeed
end

#resetObject



51
52
53
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 51

def reset
  self.position = ExcelAbstraction::CellReference.new(row: 0, col: 0)
end

#right(times = 1) ⇒ Object



30
31
32
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 30

def right(times = 1)
  goto(row, col + times)
end

#up(times = 1) ⇒ Object



18
19
20
# File 'lib/excel_templating/excel_abstraction/active_cell_reference.rb', line 18

def up(times = 1)
  goto(row - times, col)
end