Class: GMSEC::Config
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #to_xml ⇒ Object
- #values ⇒ Object
Methods included from API
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 |
# File 'lib/gmsec/config.rb', line 15 def initialize(={}) .each do |key, value| add_value(key, value) end end |
Class Method Details
.from_config_file(config_file, config_name) ⇒ Object
10 11 12 13 |
# File 'lib/gmsec/config.rb', line 10 def self.from_config_file(config_file, config_name) config = config_file.get_config(config_name) new(native_object: to_native(config)) end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/gmsec/config.rb', line 21 def [](key) get_value(key) end |
#[]=(key, value) ⇒ Object
25 26 27 |
# File 'lib/gmsec/config.rb', line 25 def []=(key, value) add_value(key, value) end |
#to_xml ⇒ Object
58 59 60 61 62 |
# File 'lib/gmsec/config.rb', line 58 def to_xml with_string_pointer do |pointer| gmsec_ConfigToXML(self, pointer, status) end end |
#values ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gmsec/config.rb', line 29 def values Enumerator.new do |y| field = GMSEC::Field.new key_buffer = FFI::Buffer.new(1024) value_buffer = FFI::Buffer.new(8*1024) key_pointer = FFI::MemoryPointer.new(key_buffer) value_pointer = FFI::MemoryPointer.new(value_buffer) gmsec_ConfigGetFirst(self, key_pointer, value_pointer, status) key = key_pointer.read_pointer.read_string_to_null unless status.is_error? value = value_pointer.read_pointer.read_string_to_null unless status.is_error? while status.code != GMSEC_CONFIG_END_REACHED && status.code == GMSEC_STATUS_NO_ERROR y << [key, value] gmsec_ConfigGetNext(self, key_pointer, value_pointer, status) key = key_pointer.read_pointer.read_string_to_null unless status.is_error? value = value_pointer.read_pointer.read_string_to_null unless status.is_error? end if status.code != GMSEC_CONFIG_END_REACHED raise RuntimeError.new("Error reading config fields : #{status}") end end end |