Module: EISCP::Dictionary::DictionaryHelpers

Included in:
EISCP::Dictionary
Defined in:
lib/eiscp/dictionary/dictionary_helpers.rb

Overview

This module provides methods to get information from the Dictionary about commands, values, zones, and models.

Instance Method Summary collapse

Instance Method Details

#command_name_to_command(name, command_zone = nil) ⇒ Object

Return the command from a given command name



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 31

def command_name_to_command(name, command_zone = nil)
  if command_zone.nil?

    @zones.each do |zone|
      @commands[zone].each_pair do |command, attrs|
        return command if attrs[:name] == name
      end
    end
    nil

  else

    @commands[command_zone].each_pair do |command, attrs|
      return command if attrs[:name] == name
    end
    nil

  end
end

#command_to_name(command) ⇒ Object

Return the human readable name of a command



20
21
22
23
24
25
26
27
28
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 20

def command_to_name(command)
  command = command.upcase
  begin
    zone = zone_from_command(command)
    @commands[zone][command][:name]
  rescue StandardError
    nil
  end
end

#command_value_name_to_value(command, value_name) ⇒ Object

Return a value from a command and value name



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 65

def command_value_name_to_value(command, value_name)
  zone = zone_from_command(command)
  @commands[zone][command][:values].each_pair do |k, v|
    if v[:name].instance_of?(String)
      return k if v[:name] == value_name.to_s
    elsif v[:name].instance_of?(Array)
      return k if v[:name].first == value_name.to_s
    end
  end
  nil
rescue StandardError
  nil
end

#command_value_to_value_name(command, value) ⇒ Object

Return a value name from a command and a value



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 52

def command_value_to_value_name(command, value)
  zone = zone_from_command(command)
  command_value = @commands[zone][command][:values][value][:name]
  if command_value.instance_of?(String)
    command_value
  elsif command_value.instance_of?(Array)
    command_value.first
  end
rescue StandardError
  nil
end

#description_from_command(command) ⇒ Object

Return a command description from a command



88
89
90
91
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 88

def description_from_command(command)
  zone = zone_from_command(command)
  @commands[zone][command][:description]
end

#description_from_command_name(name, zone) ⇒ Object

Return a command description from a command name and zone



80
81
82
83
84
85
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 80

def description_from_command_name(name, zone)
  @commands[zone].each_pair do |command, attrs|
    return @commands[zone][command][:description] if attrs[:name] == name
  end
  nil
end

#description_from_command_value(command, value) ⇒ Object

Return a value description from a command and value



94
95
96
97
98
99
100
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 94

def description_from_command_value(command, value)
  zone = zone_from_command(command)
  @commands[zone][command][:values].select do |k, v|
    return v[:description] if k == value
  end
  nil
end

#known_command?(command) ⇒ Boolean

Checks to see if the command is in the Dictionary

Returns:

  • (Boolean)


113
114
115
116
117
118
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 113

def known_command?(command)
  zone = zone_from_command(command)
  @commands[zone].include? command
rescue StandardError
  nil
end

#list_compatible_commands(modelstring) ⇒ Object

Return a list of commands compatible with a given model



103
104
105
106
107
108
109
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 103

def list_compatible_commands(modelstring)
  sets = []
  @modelsets.each_pair do |set, array|
    sets << set if array.include? modelstring
  end
  sets
end

#zone_from_command(command) ⇒ Object

Return the zone that includes the given command



10
11
12
13
14
15
16
17
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 10

def zone_from_command(command)
  @zones.each do |zone|
    @commands[zone].each_pair do |k, _|
      return zone if command == k
    end
  end
  nil
end