Class: Dullard::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/dullard/dullard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



43
44
45
# File 'lib/dullard/dullard.rb', line 43

def name
  @name
end

#workbookObject (readonly)

Returns the value of attribute workbook.



43
44
45
# File 'lib/dullard/dullard.rb', line 43

def workbook
  @workbook
end

Instance Method Details

#rowsObject



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