Class: Rhea::CommandType
- Inherits:
-
Object
- Object
- Rhea::CommandType
- Defined in:
- lib/rhea/command_type.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #displayed_format ⇒ Object
-
#initialize(key:, name:, format:) ⇒ CommandType
constructor
A new instance of CommandType.
- #input_to_command_expression(input) ⇒ Object
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
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/rhea/command_type.rb', line 3 def format @format end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/rhea/command_type.rb', line 3 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rhea/command_type.rb', line 3 def name @name end |
Class Method Details
.all ⇒ Object
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_select ⇒ Object
31 32 33 34 35 |
# File 'lib/rhea/command_type.rb', line 31 def self. all.map do |command_type| [command_type.name, command_type.key, :'data-syntax' => command_type.displayed_format] end end |
Instance Method Details
#displayed_format ⇒ Object
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 |