Class: Moon::Tabular::Partition

Inherits:
Object
  • Object
show all
Includes:
Moon::Tabular
Defined in:
lib/moon/packages/data_bags/tabular/partition.rb

Overview

Partitions are used to mask a section of a Table for editing as if it was a seperate Table, any changes done in the partition are done to the underlaying src Table, this is a nice way to trick other classes into thinking its working with a Table

Defined Under Namespace

Classes: Iterator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Moon::Tabular

#contains?, #rect, #set_by_dict, #sizes

Constructor Details

#initialize(src, selection) ⇒ Partition

Returns a new instance of Partition.

Parameters:


29
30
31
32
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 29

def initialize(src, selection)
  @src = src
  self.selection = selection
end

Instance Attribute Details

#oxInteger (readonly)

Returns:


17
18
19
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 17

def ox
  @ox
end

#oyInteger (readonly)

Returns:


19
20
21
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 19

def oy
  @oy
end

#sizeInteger (readonly)

Returns:


25
26
27
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 25

def size
  @size
end

#srcMoon::Tabular (readonly)

Returns:


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

def src
  @src
end

#xsizeInteger (readonly)

Returns:


21
22
23
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 21

def xsize
  @xsize
end

#ysizeInteger (readonly)

Returns:


23
24
25
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 23

def ysize
  @ysize
end

Instance Method Details

#[](x, y) ⇒ Integer

Parameters:

Returns:


64
65
66
67
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 64

def [](x, y)
  return default unless contains?(x, y)
  src[x + ox, y + oy]
end

#[]=(x, y, v) ⇒ Object

Parameters:


72
73
74
75
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 72

def []=(x, y, v)
  return unless contains?(x, y)
  src[x + ox, y + oy] = v
end

#defaultInteger

Returns:


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

def default
  src.default
end

#default=(default) ⇒ Object

Parameters:


40
41
42
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 40

def default=(default)
  src.default = default
end

#iterInterator

Initializes and returns an Iterator

Returns:

  • (Interator)

80
81
82
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 80

def iter
  @iter ||= Iterator.new(self)
end

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

Yield Parameters:


87
88
89
90
91
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 87

def map_with_xy
  iter.each_with_xy do |n, x, y|
    self[x, y] = yield self[x, y], x, y
  end
end

#resize(xsize, ysize) ⇒ Object

TODO:

Validate that the new size is smaller than or equal to the src


57
58
59
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 57

def resize(xsize, ysize)
  @xsize, @ysize = xsize, ysize
end

#selectionMoon::Rect

Returns:


45
46
47
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 45

def selection
  Rect.new(@ox, @oy, @xsize, @ysize)
end

#selection=(selection) ⇒ Object

Parameters:


50
51
52
53
54
# File 'lib/moon/packages/data_bags/tabular/partition.rb', line 50

def selection=(selection)
  @ox, @oy = selection.x.to_i, selection.y.to_i
  @xsize, @ysize = selection.w.to_i, selection.h.to_i
  @size = @xsize * @ysize
end