Class: Dullard::Sheet
- Inherits:
-
Object
- Object
- Dullard::Sheet
- Defined in:
- lib/dullard/dullard.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#workbook ⇒ Object
readonly
Returns the value of attribute workbook.
Instance Method Summary collapse
-
#initialize(workbook, name, id) ⇒ Sheet
constructor
A new instance of Sheet.
- #rows ⇒ Object
- #string_lookup(i) ⇒ Object
Constructor Details
#initialize(workbook, name, id) ⇒ Sheet
Returns a new instance of Sheet.
44 45 46 47 48 |
# File 'lib/dullard/dullard.rb', line 44 def initialize(workbook, name, id) @workbook = workbook @name = name @id = id end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
43 44 45 |
# File 'lib/dullard/dullard.rb', line 43 def name @name end |
#workbook ⇒ Object (readonly)
Returns the value of attribute workbook.
43 44 45 |
# File 'lib/dullard/dullard.rb', line 43 def workbook @workbook end |
Instance Method Details
#rows ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dullard/dullard.rb', line 54 def rows Enumerator.new do |y| state = :top shared = false row = nil Nokogiri::XML::Reader(@workbook.zipfs.file.open("xl/worksheets/sheet#{@id}.xml")).each do |node| if node.name == "row" and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT row = [] elsif node.name == "row" and node.node_type == Nokogiri::XML::Reader::TYPE_END_ELEMENT y << row elsif node.name == "c" and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT shared = (node.attribute("t") == "s") elsif node.value? row << (shared ? string_lookup(node.value.to_i) : node.value) end end end end |
#string_lookup(i) ⇒ Object
50 51 52 |
# File 'lib/dullard/dullard.rb', line 50 def string_lookup(i) @workbook.string_table[i] end |