Class: Coopy::TableStream

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

Instance Method Summary collapse

Constructor Details

#initialize(t) ⇒ TableStream

Returns a new instance of TableStream.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lib/coopy/table_stream.rb', line 7

def initialize(t)
  @t = t
  @at = -1
  @h = t.get_height
  @src = nil
  if @h < 0 
    meta = t.get_meta
    raise hx_raise("Cannot get meta information for table") if meta == nil
    @src = meta.get_row_stream
    raise hx_raise("Cannot iterate table") if @src == nil
  end
end

Instance Method Details

#fetchObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/lib/coopy/table_stream.rb', line 73

def fetch 
  if @at == -1 
    @at+=1
    self.fetch_columns if @src != nil
    return true
  end
  if @src != nil 
    @at = 1
    @row = self.fetch_row
    return @row != nil
  end
  @at+=1
  @at < @h
end

#fetch_columnsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lib/coopy/table_stream.rb', line 31

def fetch_columns 
  return @columns if @columns != nil
  if @src != nil 
    @columns = @src.fetch_columns
    return @columns
  end
  @columns = Array.new
  begin
    _g1 = 0
    _g = @t.get_width
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      @columns.push(@t.get_cell(i,0))
    end
  end
  @columns
end

#fetch_rowObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lib/coopy/table_stream.rb', line 50

def fetch_row 
  return @src.fetch_row if @src != nil
  return nil if @at >= @h
  row = {}
  begin
    _g1 = 0
    _g = @columns.length
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      begin
        v = @t.get_cell(i,@at)
        begin
          value = v
          row[@columns[i]] = value
        end
        v
      end
    end
  end
  row
end

#get_cell(x) ⇒ Object



88
89
90
91
92
# File 'lib/lib/coopy/table_stream.rb', line 88

def get_cell(x)
  return @columns[x] if @at == 0
  return @row[@columns[x]] if @row != nil
  @t.get_cell(x,@at)
end

#widthObject



94
95
96
97
# File 'lib/lib/coopy/table_stream.rb', line 94

def width 
  self.fetch_columns
  @columns.length
end