Class: Resistor::Options

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResistor::BasicResistor

Initializes a new BasicResistor object. The default option values is stored in the instance variables.



46
47
48
49
50
# File 'lib/resistor/options.rb', line 46

def initialize
  self.class.defaults.each do |key, val|
    instance_variable_set("@#{key}", val)
  end
end

Instance Attribute Details

#band_numberObject (readonly)

Returns the value of attribute band_number.



9
10
11
# File 'lib/resistor/options.rb', line 9

def band_number
  @band_number
end

#toleranceObject (readonly)

Returns the value of attribute tolerance.



9
10
11
# File 'lib/resistor/options.rb', line 9

def tolerance
  @tolerance
end

Class Method Details

.defaults { ... } ⇒ Hash

The default option values. ‘@defaults` is a hash of the default options.

Examples:

Sets the options in a block.

Resistor::Options.defaults do |d|
  d[:tolerance] = 0.5
  d[:band_number] = 5
end

Yields:

  • You can set the options in a block too.



22
23
24
25
# File 'lib/resistor/options.rb', line 22

def defaults(&block)
  yield @defaults if block_given?
  @defaults
end

.set_band_number(num) ⇒ Object

Sets a combination of options that is usually used.



30
31
32
33
34
35
36
37
38
39
# File 'lib/resistor/options.rb', line 30

def set_band_number(num)
  case num
  when 4
    @defaults[:band_number] = 4
    @defaults[:tolerance] = 5.0
  when 5
    @defaults[:band_number] = 5
    @defaults[:tolerance] = 1.0
  end
end