Class: Variable

Inherits:
Struct
  • Object
show all
Defined in:
lib/strom/variable.rb

Direct Known Subclasses

Ampere, Ohm, Volt

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



1
2
3
# File 'lib/strom/variable.rb', line 1

def value
  @value
end

Instance Method Details

#and(other) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/strom/variable.rb', line 2

def and(other)
  current = resistance = voltage = nil

  [self, other].each do |element|
    case element
    when Ampere
      current = element.value
    when Ohm
      resistance = element.value
    when Volt
      voltage = element.value
    end
  end

  if current.nil?
    Ampere.new(voltage / resistance)
  elsif resistance.nil?
    Ohm.new(voltage / current)
  elsif voltage.nil?
    Volt.new(current * resistance)
  end
end