Class: Rhea::CommandType

Inherits:
Object
  • Object
show all
Defined in:
lib/rhea/command_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, name:, format:) ⇒ CommandType

Returns a new instance of CommandType.



5
6
7
8
9
# File 'lib/rhea/command_type.rb', line 5

def initialize(key:, name:, format:)
  self.key = key
  self.name = name
  self.format = format
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/rhea/command_type.rb', line 3

def format
  @format
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/rhea/command_type.rb', line 3

def key
  @key
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/rhea/command_type.rb', line 3

def name
  @name
end

Class Method Details

.allObject



19
20
21
22
23
# File 'lib/rhea/command_type.rb', line 19

def self.all
  @all ||= Rhea.configuration.command_types.map do |attributes|
    new(attributes)
  end
end

.find(key) ⇒ Object



25
26
27
28
29
# File 'lib/rhea/command_type.rb', line 25

def self.find(key)
  command_type = all.find { |command_type| command_type.key == key }
  raise "Invalid key: #{key}" unless command_type
  command_type
end

.options_for_selectObject



31
32
33
34
35
# File 'lib/rhea/command_type.rb', line 31

def self.options_for_select
  all.map do |command_type|
    [command_type.name, command_type.key, :'data-syntax' => command_type.displayed_format]
  end
end

Instance Method Details

#displayed_formatObject



15
16
17
# File 'lib/rhea/command_type.rb', line 15

def displayed_format
  format.gsub('$INPUT', '$input')
end

#input_to_command_expression(input) ⇒ Object



11
12
13
# File 'lib/rhea/command_type.rb', line 11

def input_to_command_expression(input)
  format.gsub('$INPUT', input)
end