class Resistor::Options
Attributes
band_number[R]
tolerance[R]
Public Class Methods
defaults() { |defaults| ... }
click to toggle source
The default option values. ‘@defaults` is a hash of the default options.
@yield You can set the options in a block too. @return [Hash] @example Sets the options in a block.
Resistor::Options.defaults do |d| d[:tolerance] = 0.5 d[:band_number] = 5 end
# File lib/resistor/options.rb, line 22 def defaults(&block) yield @defaults if block_given? @defaults end
new()
click to toggle source
Initializes a new BasicResistor
object. The default option values is stored in the instance variables.
@return [Resistor::BasicResistor]
# File lib/resistor/options.rb, line 46 def initialize self.class.defaults.each do |key, val| instance_variable_set("@#{key}", val) end end
set_band_number(num)
click to toggle source
Sets a combination of options that is usually used.
@param num [Integer] The number of the color bands
# 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