Class: AsiBod::Asi

Inherits:
Object
  • Object
show all
Defined in:
lib/asi_bod/asi.rb

Overview

Handle reading in ASI ObjectDictionary and doing operations on it

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • params (Hash) (defaults to: { asi_file: default_file_path })


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_dataObject (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_dataObject (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

#noriObject (readonly)

Returns the value of attribute nori.



8
9
10
# File 'lib/asi_bod/asi.rb', line 8

def nori
  @nori
end

#raw_dataObject (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_pathObject

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.expand_path('../../../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