class Spreet::Sheets
Public Class Methods
new(document)
click to toggle source
# File lib/spreet/sheets.rb, line 5 def initialize(document) raise ArgumentError.new("Must be a Document") unless document.is_a?(Document) @document = document @array = [] end
Public Instance Methods
[](sheet)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/spreet/sheets.rb, line 11 def count @array.size end
each() { |item| ... }
click to toggle source
# File lib/spreet/sheets.rb, line 55 def each(&block) for item in @array yield item end end
index(name_or_sheet)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/spreet/sheets.rb, line 38 def remove(sheet) @array.delete_at(index(sheet)) end