Class: AsiBod::Dict

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

Overview

Manipulate the unified Hash that can contain the data from ASIObjectDictionary or BOD

Class Method Summary collapse

Class Method Details

.find_by_key_substring(dict, key, search_value, output_keys) ⇒ Array<Hash>

Find a node in the dict by the value of the specified key



14
15
16
17
18
19
# File 'lib/asi_bod/dict.rb', line 14

def self.find_by_key_substring(dict, key, search_value, output_keys)
  dict.each_with_object({}) do |(k, v), memo|
    next if v[key].nil?
    memo[k] = node_line(v, output_keys) if v[key].to_s.include? search_value
  end
end

.merge(asi, bod) ⇒ Object

Merge the descriptions from ASIObjectDictionary Hash of Hashes into BOD Hash of Hashes This is not used often. Allowed the creation of the BODm.json file which has the ASIObjectDictionary Descriptions merged in



44
45
46
47
48
49
50
51
52
53
# File 'lib/asi_bod/dict.rb', line 44

def self.merge(asi, bod)
  bod.each_with_object({}) do |(address, node), memo|
    memo[address] = node
    if (asi[address][:description].nil? ||
        asi[address][:description].include?('Reserved') rescue true)
      memo[address][:description] = nil
    end
    memo[address][:description] = asi[address][:description]
  end
end

.node_line(node, keys) ⇒ Object

Takes a node and returns an array of elements in the order the keys specify



24
25
26
# File 'lib/asi_bod/dict.rb', line 24

def self.node_line(node, keys)
  keys.map { |k| node[k] }.join(", ")
end

.specific_keys_per_node(dict, keys) ⇒ Hash<Symbol>, <Hash>

Takes a hash of results (subset of a Dict Hash) and puts a result per line with only the keys specified



33
34
35
36
37
# File 'lib/asi_bod/dict.rb', line 33

def self.specific_keys_per_node(dict, keys)
  dict.each_with_object({}) do |(key, node), memo|
    memo[key] = Dict.node_line(node, keys)
  end
end