Class: CommandTimer::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/command_timer/parser.rb

Class Method Summary collapse

Class Method Details

.parse(yml_path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/command_timer/parser.rb', line 5

def self.parse(yml_path)
  yml_path += ".yml" unless yml_path.end_with?('.yml')
  yml = YAML.load_file(yml_path)
  commands = []
  yml.each do |cell|
    data = cell[1]
    command = Command.new
    data.each do |k, v|
      if ['content', 'observer'].include?(k)
        command.send("#{k}=", parse_commands(v))
      else
        command.send("#{k}=", v)
      end
    end
    commands << command
  end
  commands
end

.parse_commands(text) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/command_timer/parser.rb', line 24

def self.parse_commands(text)
  commands = ''
  text.each_line do |line|
    commands += line.strip
    commands += ';' unless line.end_with?(';')
  end
  commands
end