Class: Moon::Tabular::IteratorBase

Inherits:
Object
  • Object
show all
Defined in:
lib/moon/packages/data_bags/tabular/iterator_base.rb

Overview

Iteratable Tabular objects are expected to respond to:

xsize -> Integer
ysize -> Integer
[](x, y) -> Integer

Direct Known Subclasses

Moon::Table::Iterator, Partition::Iterator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ IteratorBase

Returns a new instance of IteratorBase.

Parameters:


18
19
20
# File 'lib/moon/packages/data_bags/tabular/iterator_base.rb', line 18

def initialize(src)
  @src = src
end

Instance Attribute Details

#srcMoon::Tabular (readonly)

Returns:


15
16
17
# File 'lib/moon/packages/data_bags/tabular/iterator_base.rb', line 15

def src
  @src
end

Instance Method Details

#each {|value| ... } ⇒ Object

Yield Parameters:


35
36
37
# File 'lib/moon/packages/data_bags/tabular/iterator_base.rb', line 35

def each
  each_with_xy { |n, _, _| yield n }
end

#each_column {|value, x| ... } ⇒ Object

Iterates and yields each columns data

Yield Parameters:


54
55
56
57
58
59
# File 'lib/moon/packages/data_bags/tabular/iterator_base.rb', line 54

def each_column
  ys = src.ysize
  src.xsize.times do |x|
    yield ys.times.map { |y| src[x, y] }
  end
end

#each_row {|value, y| ... } ⇒ Object

Iterates and yields each rows data

Yield Parameters:


43
44
45
46
47
48
# File 'lib/moon/packages/data_bags/tabular/iterator_base.rb', line 43

def each_row
  xs = src.xsize
  src.ysize.times do |y|
    yield xs.times.map { |x| src[x, y] }
  end
end

#each_with_xy {|value, x, y| ... } ⇒ Object

Yield Parameters:


25
26
27
28
29
30
31
32
# File 'lib/moon/packages/data_bags/tabular/iterator_base.rb', line 25

def each_with_xy
  xs, ys = src.xsize, src.ysize
  ys.times do |y|
    xs.times do |x|
      yield src[x, y], x, y
    end
  end
end