Class: Eletro::Capacitor
- Includes:
- ColorCode
- Defined in:
- lib/eletro/capacitor.rb
Constant Summary
Constants included from ColorCode
Eletro::ColorCode::CODE, Eletro::ColorCode::COLORS, Eletro::ColorCode::PRECISION
Instance Attribute Summary collapse
-
#polarized ⇒ Object
Returns the value of attribute polarized.
Attributes included from ColorCode
Attributes inherited from Part
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(*args) ⇒ Capacitor
constructor
A new instance of Capacitor.
- #mult ⇒ Object
- #parse(txt) ⇒ Object
- #polarized? ⇒ Boolean
- #unit ⇒ Object
Methods included from ColorCode
#bold, #calc, #color2value, #parse_color_code, #rgblize, #value2color
Methods inherited from Part
#*, #+, #-, #/, #abs, #coerce, #method_missing, #round, #to_f, #to_i, #to_s
Constructor Details
#initialize(*args) ⇒ Capacitor
Returns a new instance of Capacitor.
11 12 13 |
# File 'lib/eletro/capacitor.rb', line 11 def initialize(*args) parse_color_code(args.join) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Eletro::Part
Instance Attribute Details
#polarized ⇒ Object
Returns the value of attribute polarized.
7 8 9 |
# File 'lib/eletro/capacitor.rb', line 7 def polarized @polarized end |
Instance Method Details
#format ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/eletro/capacitor.rb', line 34 def format m = 'p' mult.keys.reverse.each do |k| m = k if value >= mult[k] end out = "%g#{m}#{unit}" % (value/mult[m]) #.round out += " ± #{@precision}%" if @precision out end |
#mult ⇒ Object
30 31 32 |
# File 'lib/eletro/capacitor.rb', line 30 def mult { 'u' => 10e-6, 'n' => 10e-9, 'p' => 10e-12 } end |
#parse(txt) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/eletro/capacitor.rb', line 15 def parse txt if m = txt.match(/#{mult.keys.join('|')}/) txt.gsub!(/#{m[0]}/, ".") m = mult[m[0]] else st, nd, m = txt.split(//) m = m.to_i #(10**-(m.to_i)) end ("#{st}#{nd}#{'0' * m}").to_f * mult['p'] end |
#polarized? ⇒ Boolean
44 45 46 |
# File 'lib/eletro/capacitor.rb', line 44 def polarized? !!@polarized end |
#unit ⇒ Object
26 27 28 |
# File 'lib/eletro/capacitor.rb', line 26 def unit "F" end |