Class: Electric::Resistor

Inherits:
Object
  • Object
show all
Defined in:
lib/electric/resistor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#firstObject

Returns the value of attribute first.



3
4
5
# File 'lib/electric/resistor.rb', line 3

def first
  @first
end

#fourthObject

Returns the value of attribute fourth.



3
4
5
# File 'lib/electric/resistor.rb', line 3

def fourth
  @fourth
end

#secondObject

Returns the value of attribute second.



3
4
5
# File 'lib/electric/resistor.rb', line 3

def second
  @second
end

#thirdObject

Returns the value of attribute third.



3
4
5
# File 'lib/electric/resistor.rb', line 3

def third
  @third
end

Instance Method Details

#human_readableObject



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