Class: Eletro::Ohm
- Inherits:
-
Object
- Object
- Eletro::Ohm
- Defined in:
- lib/eletro/ohm.rb
Constant Summary collapse
- VALUES =
[:v, :r, :i]
Instance Attribute Summary collapse
-
#i ⇒ Object
Returns the value of attribute i.
-
#p ⇒ Object
Returns the value of attribute p.
-
#r ⇒ Object
Returns the value of attribute r.
-
#v ⇒ Object
def r calc(:r) || @r = v / i end.
Instance Method Summary collapse
- #calc(v, data = nil) ⇒ Object
-
#initialize(*args) ⇒ Ohm
constructor
A new instance of Ohm.
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Ohm
Returns a new instance of Ohm.
8 9 10 |
# File 'lib/eletro/ohm.rb', line 8 def initialize(*args) args.each { |a| puts a.inspect } end |
Instance Attribute Details
#i ⇒ Object
Returns the value of attribute i.
5 6 7 |
# File 'lib/eletro/ohm.rb', line 5 def i @i end |
#p ⇒ Object
Returns the value of attribute p.
5 6 7 |
# File 'lib/eletro/ohm.rb', line 5 def p @p end |
#r ⇒ Object
Returns the value of attribute r.
5 6 7 |
# File 'lib/eletro/ohm.rb', line 5 def r @r end |
#v ⇒ Object
def r
calc(:r) || @r = v / i
end
17 18 19 |
# File 'lib/eletro/ohm.rb', line 17 def v @v end |
Instance Method Details
#calc(v, data = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/eletro/ohm.rb', line 29 def calc(v, data=nil) if data # instance_variable_set("@#{v}", BigDecimal.new(data.to_s)) # puts data.class instance_variable_set("@#{v}", data) else # val = instance_variable_get("@#{v}") # return val if val (VALUES - [v]).select { |v| instance_variable_get("@#{v}").nil? }.empty? # raise "Can't call dunno #{v}" unless instance_variable_get("@#{v}") # end end end |
#to_s ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/eletro/ohm.rb', line 45 def to_s o = "" VALUES.each do |v| if val = send(v) o += "#{val} " + { :r => "Ω", :i => "A", :v => "V"}[v] end end o end |