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



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

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
    return nil

  else

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

  end
end

#command_to_name(command) ⇒ Object

Return the human readable name of a command



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

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

#command_value_name_to_value(command, value_name) ⇒ Object

Return a value from a command and value name



60
61
62
63
64
65
66
67
68
69
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 60

def command_value_name_to_value(command, value_name)
  begin
    zone = zone_from_command(command)
    @commands[zone][command][:values].each_pair do |k, v|
      return k if v[:name] == value_name.to_s
    end
  rescue
    nil
  end
end

#command_value_to_value_name(command, value) ⇒ Object

Return a value name from a command and a value



50
51
52
53
54
55
56
57
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 50

def command_value_to_value_name(command, value)
  begin
    zone = zone_from_command(command)
    @commands[zone][command][:values][value][:name]
  rescue
    nil
  end
end

#description_from_command(command) ⇒ Object

Return a command description from a command



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

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



72
73
74
75
76
77
78
79
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 72

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

#description_from_command_value(command, value) ⇒ Object

Return a value description from a command and value



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

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)


107
108
109
110
111
112
113
114
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 107

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

#list_compatible_commands(modelstring) ⇒ Object

Return a list of commands compatible with a given model



97
98
99
100
101
102
103
# File 'lib/eiscp/dictionary/dictionary_helpers.rb', line 97

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



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

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