Class: Spreet::Sheets
- Inherits:
-
Object
- Object
- Spreet::Sheets
- Defined in:
- lib/spreet/sheets.rb
Instance Method Summary collapse
- #[](sheet) ⇒ Object
- #add(name = nil, position = -1)) ⇒ Object
- #count ⇒ Object
- #each(&block) ⇒ Object
- #index(name_or_sheet) ⇒ Object
-
#initialize(document) ⇒ Sheets
constructor
A new instance of Sheets.
- #move(sheet, shift = 0) ⇒ Object
- #move_at(sheet, position = -1)) ⇒ Object
- #remove(sheet) ⇒ Object
Constructor Details
Instance Method Details
#[](sheet) ⇒ Object
33 34 35 36 |
# File 'lib/spreet/sheets.rb', line 33 def [](sheet) sheet = index(sheet) return (sheet.is_a?(Integer) ? @array[sheet] : nil) end |
#add(name = nil, position = -1)) ⇒ Object
27 28 29 30 31 |
# File 'lib/spreet/sheets.rb', line 27 def add(name=nil, position=-1) sheet = Sheet.new(@document, name) @array.insert(position, sheet) return sheet end |
#count ⇒ Object
11 12 13 |
# File 'lib/spreet/sheets.rb', line 11 def count @array.size end |
#each(&block) ⇒ Object
55 56 57 58 59 |
# File 'lib/spreet/sheets.rb', line 55 def each(&block) for item in @array yield item end end |
#index(name_or_sheet) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/spreet/sheets.rb', line 15 def index(name_or_sheet) if name_or_sheet.is_a? String @array.each_index do |i| return i if @array[i].name == name_or_sheet end elsif name_or_sheet.is_a? Integer return (@array[name_or_sheet].nil? ? nil : name_or_sheet) else return @array.index(name_or_sheet) end end |
#move(sheet, shift = 0) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/spreet/sheets.rb', line 42 def move(sheet, shift=0) position = index(sheet) + shift position = 0 if position < 0 position = self.count-1 if position >= self.count move_at(sheet, position) end |
#move_at(sheet, position = -1)) ⇒ Object
49 50 51 52 53 |
# File 'lib/spreet/sheets.rb', line 49 def move_at(sheet, position=-1) if i = index(sheet) @array.insert(position, @array.delete_at(i)) end end |
#remove(sheet) ⇒ Object
38 39 40 |
# File 'lib/spreet/sheets.rb', line 38 def remove(sheet) @array.delete_at(index(sheet)) end |