Class: Speck::Battery

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

Overview

A ‘Battery` of `Speck`s is a set of specks which should be executed together, and which interdepend upon other `Speck`s in the battery. `Batteries` are recursive structures; that is, a `Battery` may have sub– `Batteries` for relevant objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBattery

Returns a new instance of Battery.



12
13
14
15
# File 'lib/speck/battery.rb', line 12

def initialize
  @specks = Array.new
  @targets = Hash.new
end

Instance Attribute Details

#specksObject (readonly)

Returns the value of attribute specks.



9
10
11
# File 'lib/speck/battery.rb', line 9

def specks
  @specks
end

#targetsObject (readonly)

Returns the value of attribute targets.



10
11
12
# File 'lib/speck/battery.rb', line 10

def targets
  @targets
end

Instance Method Details

#<<(speck) ⇒ Object



17
18
19
20
21
# File 'lib/speck/battery.rb', line 17

def << speck
  @specks << speck
  @targets[speck.target] ||= Battery.new
  return self
end

#[](object) ⇒ Object



23
24
25
# File 'lib/speck/battery.rb', line 23

def [] object
  return @targets[object]
end