Class: AsiBod::Asi
- Inherits:
-
Object
- Object
- AsiBod::Asi
- Defined in:
- lib/asi_bod/asi.rb
Overview
Handle reading in ASI ObjectDictionary and doing operations on it
Instance Attribute Summary collapse
-
#array_data ⇒ Object
readonly
Returns the value of attribute array_data.
-
#hash_data ⇒ Object
readonly
Returns the value of attribute hash_data.
-
#nori ⇒ Object
readonly
Returns the value of attribute nori.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
Class Method Summary collapse
-
.default_file_path ⇒ Object
Returns the path to the default ASIObjectDictionary.xml file.
Instance Method Summary collapse
-
#array_data_to_hash(array_data) ⇒ Object
Convert the array of hashes to a hash with the address as primary key.
- #clean_node(node) ⇒ Object
-
#initialize(params = { asi_file: default_file_path }) ⇒ Asi
constructor
Asi.new reads in the source file for the ASIObjectDictionary and creates an internal Hash.
Constructor Details
#initialize(params = { asi_file: default_file_path }) ⇒ Asi
Asi.new reads in the source file for the ASIObjectDictionary and creates an internal Hash
21 22 23 24 25 26 |
# File 'lib/asi_bod/asi.rb', line 21 def initialize(params = { asi_file: default_file_path }) @nori = Nori.new @raw_data = @nori.parse(File.read(params[:asi_file])) @array_data = @raw_data['InternalAppEntity']['Parameters'].first[1] @hash_data = array_data_to_hash(@array_data) end |
Instance Attribute Details
#array_data ⇒ Object (readonly)
Returns the value of attribute array_data.
10 11 12 |
# File 'lib/asi_bod/asi.rb', line 10 def array_data @array_data end |
#hash_data ⇒ Object (readonly)
Returns the value of attribute hash_data.
11 12 13 |
# File 'lib/asi_bod/asi.rb', line 11 def hash_data @hash_data end |
#nori ⇒ Object (readonly)
Returns the value of attribute nori.
8 9 10 |
# File 'lib/asi_bod/asi.rb', line 8 def nori @nori end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
9 10 11 |
# File 'lib/asi_bod/asi.rb', line 9 def raw_data @raw_data end |
Class Method Details
.default_file_path ⇒ Object
Returns the path to the default ASIObjectDictionary.xml file
14 15 16 |
# File 'lib/asi_bod/asi.rb', line 14 def self.default_file_path File.('../../../ASIObjectDictionary.xml', __FILE__) end |
Instance Method Details
#array_data_to_hash(array_data) ⇒ Object
Convert the array of hashes to a hash with the address as primary key
29 30 31 32 33 |
# File 'lib/asi_bod/asi.rb', line 29 def array_data_to_hash(array_data) array_data.each_with_object({}) do |node, memo| memo[node['Address'].to_i] = clean_node(node) end end |
#clean_node(node) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/asi_bod/asi.rb', line 35 def clean_node(node) node.each_with_object({}) do |(k,v), memo| next if k == "@FaultIndicator" || k == "BitField" # Skip these pairs key = k.sub(k[0], k[0].downcase) # Make it uncapitalized memo[key.to_sym] = v end end |