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(phrase) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Generator
Returns a new instance of Generator.
3 4 5 6 7 8 9 10 11 12 13 |
# 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["repetitions"] ||= 1 end |
Instance Method Details
#settings ⇒ Object
25 26 27 |
# File 'lib/vail/generator.rb', line 25 def settings @config.reject { |key, value| [Dot,Dash].include? key } end |
#to_morse(phrase) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/vail/generator.rb', line 15 def to_morse(phrase) instructions = build_instructions(phrase) (@config["repetitions"].times.inject([]) { |r,i| r << instructions }).each do |instruction_set| instruction_set.each do |i| execute_instruction(i) end end end |