Class: YamlBot::ParseBot

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml_bot/parse_bot.rb

Class Method Summary collapse

Class Method Details

.get_object_value(yaml, key_addr) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/yaml_bot/parse_bot.rb', line 3

def self.get_object_value(yaml, key_addr)
  if !key_addr.index('.').nil? && key_addr.index('.') >= 0
    key1, key2 = key_addr.split('.', 2)
    return get_object_value(yaml[key1], key2) if !yaml[key1].nil? && yaml[key1].instance_of?(Hash)
    return nil
  end

  return to_boolean(yaml[key_addr]) if %w(true false).include?(yaml[key_addr])
  yaml[key_addr]
rescue StandardError => e
  puts "Caught exception #{e}!"
end

.to_boolean(val) ⇒ Object



18
19
20
# File 'lib/yaml_bot/parse_bot.rb', line 18

def self.to_boolean(val)
  val == 'true'
end