Class: Vail::Generator
- Inherits:
-
Object
- Object
- Vail::Generator
- Defined in:
- lib/vail/generator.rb
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Generator
constructor
A new instance of Generator.
- #settings ⇒ Object
- #to_morse(text) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Generator
Returns a new instance of Generator.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vail/generator.rb', line 3 def initialize(config={}) config = YAML.load(IO.read(ConfigPath)) if config.empty? @config = config.merge ( { Dot => { "duration" => config["dot"]["duration"], "pause" => config["dot"]["pause"] }, Dash => { "duration" => config["dash"]["duration"], "pause" => config["dash"]["pause"]} } ) @config.merge! ( case @config["repetitions"] when Hash {} when Fixnum { "repetitions" => { "repeat" => (@config["repetitions"] - 1), "pause" => 800 } } when NilClass { "repetitions" => { "repeat" => 0, "pause" => 800 } } end ) end |
Instance Method Details
#settings ⇒ Object
33 34 35 |
# File 'lib/vail/generator.rb', line 33 def settings @config.reject { |key, value| [Dot,Dash].include? key } end |
#to_morse(text) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/vail/generator.rb', line 25 def to_morse(text) convert_to_instructions(text).each do |instruction_set| instruction_set.each do |i| execute_instruction(i) end end end |