Class: Spreet::Sheet
- Inherits:
-
Object
- Object
- Spreet::Sheet
- Defined in:
- lib/spreet/sheet.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#current_row ⇒ Object
Returns the value of attribute current_row.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #[]=(*args) ⇒ Object
- #bound ⇒ Object
-
#cell(*args) ⇒ Object
Find or build cell.
- #each_row(&block) ⇒ Object
-
#initialize(document, name = nil) ⇒ Sheet
constructor
A new instance of Sheet.
-
#move_higher(increment = 1) ⇒ Object
Moves the sheet higher in the list of sheets.
-
#move_lower(increment = 1) ⇒ Object
Moves the sheet lower in the list of sheets.
-
#move_to(position) ⇒ Object
Moves the sheet to an other position in the list of sheets.
- #next_row(increment = 1) ⇒ Object
- #previous_row(increment = 1) ⇒ Object
- #remove!(coordinates) ⇒ Object
- #row(*args) ⇒ Object
- #rows(index) ⇒ Object
Constructor Details
#initialize(document, name = nil) ⇒ Sheet
Returns a new instance of Sheet.
7 8 9 10 11 12 13 14 |
# File 'lib/spreet/sheet.rb', line 7 def initialize(document, name=nil) @document = document self.name = name raise ArgumentError.new("Must be a Document") unless document.is_a? Document @current_row = 0 @cells = {} # BigArray::Cells.new @bound = compute_bound end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/spreet/sheet.rb', line 4 def columns @columns end |
#current_row ⇒ Object
Returns the value of attribute current_row.
5 6 7 |
# File 'lib/spreet/sheet.rb', line 5 def current_row @current_row end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
4 5 6 |
# File 'lib/spreet/sheet.rb', line 4 def document @document end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/spreet/sheet.rb', line 4 def name @name end |
Instance Method Details
#[](*args) ⇒ Object
35 36 37 38 39 |
# File 'lib/spreet/sheet.rb', line 35 def [](*args) coord = Coordinates.new(*args) @cells[coord.to_i] ||= Cell.new(self, coord) return @cells[coord.to_i] end |
#[]=(*args) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/spreet/sheet.rb', line 41 def []=(*args) value = args.delete_at(-1) cell = self[*args] cell.value = value @updated = true end |
#bound ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/spreet/sheet.rb', line 77 def bound if @updated compute_bound else @bound end end |
#cell(*args) ⇒ Object
Find or build cell
73 74 75 |
# File 'lib/spreet/sheet.rb', line 73 def cell(*args) return c end |
#each_row(&block) ⇒ Object
66 67 68 69 70 |
# File 'lib/spreet/sheet.rb', line 66 def each_row(&block) for j in 0..bound.y yield rows(j) end end |
#move_higher(increment = 1) ⇒ Object
Moves the sheet higher in the list of sheets
97 98 99 |
# File 'lib/spreet/sheet.rb', line 97 def move_higher(increment=1) @document.sheets.move(self, increment) end |
#move_lower(increment = 1) ⇒ Object
Moves the sheet lower in the list of sheets
102 103 104 |
# File 'lib/spreet/sheet.rb', line 102 def move_lower(increment=1) @document.sheets.move(self, -increment) end |
#move_to(position) ⇒ Object
Moves the sheet to an other position in the list of sheets
92 93 94 |
# File 'lib/spreet/sheet.rb', line 92 def move_to(position) @document.sheets.move_at(self, position) end |
#next_row(increment = 1) ⇒ Object
27 28 29 |
# File 'lib/spreet/sheet.rb', line 27 def next_row(increment = 1) @current_row += increment end |
#previous_row(increment = 1) ⇒ Object
31 32 33 |
# File 'lib/spreet/sheet.rb', line 31 def previous_row(increment = 1) @current_row -= increment end |
#remove!(coordinates) ⇒ Object
85 86 87 88 89 |
# File 'lib/spreet/sheet.rb', line 85 def remove!(coordinates) raise ArgumentError.new("Must be a Coordinates") unless document.is_a?(Coordinates) @cells.delete(coordinates.to_i) @updated = true end |
#row(*args) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/spreet/sheet.rb', line 48 def row(*args) = {} = args.delete_at(-1) if args[-1].is_a? Hash row = [:row] || @current_row args.each_index do |index| self[index, row] = args[index] end next_row end |
#rows(index) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/spreet/sheet.rb', line 58 def rows(index) row = [] for i in 0..bound.x row[i] = self[i, index] end return row end |