Class: Electric::Resistor
- Inherits:
-
Object
- Object
- Electric::Resistor
- Defined in:
- lib/electric/resistor.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
Returns the value of attribute first.
-
#fourth ⇒ Object
Returns the value of attribute fourth.
-
#second ⇒ Object
Returns the value of attribute second.
-
#third ⇒ Object
Returns the value of attribute third.
Instance Method Summary collapse
- #human_readable ⇒ Object
-
#initialize(first = "black", second = "black", third = "black", fourth = "gold") ⇒ Resistor
constructor
A new instance of Resistor.
Constructor Details
#initialize(first = "black", second = "black", third = "black", fourth = "gold") ⇒ Resistor
Returns a new instance of Resistor.
5 6 7 8 9 10 |
# File 'lib/electric/resistor.rb', line 5 def initialize(first = "black", second = "black", third = "black", fourth = "gold") @first = first @second = second @third = third @fourth = fourth end |
Instance Attribute Details
#first ⇒ Object
Returns the value of attribute first.
3 4 5 |
# File 'lib/electric/resistor.rb', line 3 def first @first end |
#fourth ⇒ Object
Returns the value of attribute fourth.
3 4 5 |
# File 'lib/electric/resistor.rb', line 3 def fourth @fourth end |
#second ⇒ Object
Returns the value of attribute second.
3 4 5 |
# File 'lib/electric/resistor.rb', line 3 def second @second end |
#third ⇒ Object
Returns the value of attribute third.
3 4 5 |
# File 'lib/electric/resistor.rb', line 3 def third @third end |
Instance Method Details
#human_readable ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/electric/resistor.rb', line 12 def human_readable if value >= 1000000 "#{round_for(value / 1000000.0)}M ohms#{color_to_tolerance(@fourth)}" elsif value >= 1000 "#{round_for(value / 1000.0)}K ohms#{color_to_tolerance(@fourth)}" else "#{value} ohms#{color_to_tolerance(@fourth)}" end end |