Class: Workbook::Sheet
- Inherits:
-
Array
- Object
- Array
- Workbook::Sheet
- Defined in:
- lib/workbook/sheet.rb
Overview
A Sheet is a container of tables
Instance Method Summary collapse
-
#book ⇒ Workbook::Book
Returns the book this sheet belongs to.
- #book=(b) ⇒ Object
-
#clone ⇒ Workbook::Sheet
clones itself and the tables it contains.
-
#create_or_open_table_at(index) ⇒ Object
Create or open the existing table at an index value.
-
#delete_all ⇒ Workbook::Table
Removes all lines from this table.
-
#has_contents? ⇒ Boolean
Returns true if the first table of this sheet contains anything.
-
#initialize(table = Workbook::Table.new([], self), book = nil, options = {}) ⇒ Workbook::Sheet
constructor
Initialize a new sheet.
-
#name ⇒ String
Returns the name of this sheet.
-
#name=(name) ⇒ String
Set the name of this sheet.
-
#table ⇒ Workbook::Table
Returns the first table of this sheet.
-
#table=(table, options = {}) ⇒ Workbook::Table
Set the first table of this sheet with a table or array of cells/values.
Constructor Details
#initialize(table = Workbook::Table.new([], self), book = nil, options = {}) ⇒ Workbook::Sheet
Initialize a new sheet
15 16 17 18 19 20 21 22 23 |
# File 'lib/workbook/sheet.rb', line 15 def initialize table=Workbook::Table.new([], self), book=nil, ={} if table.is_a? Workbook::Table push table else push Workbook::Table.new(table, self, ) end self.book = book return self end |
Instance Method Details
#book ⇒ Workbook::Book
Returns the book this sheet belongs to
70 71 72 73 74 75 76 77 |
# File 'lib/workbook/sheet.rb', line 70 def book if @book return @book else self.book = Workbook::Book.new(self) return @book end end |
#book=(b) ⇒ Object
79 80 81 |
# File 'lib/workbook/sheet.rb', line 79 def book= b @book = b end |
#clone ⇒ Workbook::Sheet
clones itself and the tables it contains
93 94 95 96 97 98 99 |
# File 'lib/workbook/sheet.rb', line 93 def clone s = self c = super c.delete_all s.each{|t| c << t.clone} return c end |
#create_or_open_table_at(index) ⇒ Object
Create or open the existing table at an index value
104 105 106 107 108 109 |
# File 'lib/workbook/sheet.rb', line 104 def create_or_open_table_at index t = self[index] t = self[index] = Workbook::Table.new if t == nil t.sheet = self t end |
#delete_all ⇒ Workbook::Table
Removes all lines from this table
86 87 88 |
# File 'lib/workbook/sheet.rb', line 86 def delete_all self.delete_if{|b| true} end |
#has_contents? ⇒ Boolean
Returns true if the first table of this sheet contains anything
28 29 30 |
# File 'lib/workbook/sheet.rb', line 28 def has_contents? table.has_contents? end |
#name ⇒ String
Returns the name of this sheet
42 43 44 |
# File 'lib/workbook/sheet.rb', line 42 def name @name ||= "Sheet #{book.index(self)+1}" end |
#name=(name) ⇒ String
Set the name of this sheet
50 51 52 |
# File 'lib/workbook/sheet.rb', line 50 def name= name @name = name end |
#table ⇒ Workbook::Table
Returns the first table of this sheet
35 36 37 |
# File 'lib/workbook/sheet.rb', line 35 def table first end |
#table=(table, options = {}) ⇒ Workbook::Table
Set the first table of this sheet with a table or array of cells/values
58 59 60 61 62 63 64 65 |
# File 'lib/workbook/sheet.rb', line 58 def table= table, ={} if table.is_a? Workbook::Table self[0] = table else self[0] = Workbook::Table.new(table, self, ) end return table end |