Class: Calypso::YAMLParser

Inherits:
IParser
  • Object
show all
Defined in:
lib/calypso/yamlparser.rb

Overview

YAML parser library

Instance Attribute Summary

Attributes inherited from IParser

#hardware, #tests

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ YAMLParser

Create a new YAML parser.

Parameters:

  • file (String)

    Path to the configuration file.



33
34
35
# File 'lib/calypso/yamlparser.rb', line 33

def initialize(file)
  super
end

Instance Method Details

#parsenil

Parse the configuration file.

Returns:

  • (nil)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/calypso/yamlparser.rb', line 40

def parse
  obj = YAML.load_file(@file)
  hardware = Hash.new
  tests = Hash.new

  obj['hardware'].each do |key, value|
    hw = Calypso::Hardware.new(key, value['name'], value['cpu'])
    hardware[key] = hw
  end

  obj['unit-tests'].each do |key, value|
    hw = hardware[value['hardware']]
    port = value['port']
    baud = value['baud']
    serial = Calypso::SerialPortData.new(port, baud)
    tst = Calypso::UnitTest.new(value, serial, hw)
    tests[key] = tst
    hw.add_test tst
  end

  set_hardware(hardware)
  set_tests(tests)
end