Sha256: 161990d192ce344d8bdc4f0497bcb74b491f236d95f9454d6333c70a87bfd0c3

Contents?: true

Size: 595 Bytes

Versions: 1

Compression:

Stored size: 595 Bytes

Contents

class Variable < Struct.new(:value)
  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
end

class Ampere < Variable
end

class Ohm < Variable
end

class Volt < Variable
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
strom-0.0.1 lib/strom/variable.rb