Class: Confinicky::Parsers::Command
- Inherits:
-
Object
- Object
- Confinicky::Parsers::Command
- Defined in:
- lib/confinicky/parsers/command.rb
Overview
A simple class that parses a line of shell code to into a classified and attributed string.
Constant Summary collapse
- EXPORT_COMMAND =
'export'
- ALIAS_COMMAND =
'alias'
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the command.
-
#value ⇒ Object
readonly
The assigned value of the command.
Instance Method Summary collapse
-
#alias? ⇒ Boolean
Returns true if the line of code matches an alias command.
- #append(value) ⇒ Object
- #closed? ⇒ Boolean
-
#export? ⇒ Boolean
Returns true if the line of code matches an export command.
-
#initialize(line: nil) ⇒ Command
constructor
Takes a line of code as a parameter and performs classification.
-
#line? ⇒ Boolean
The command should be regarded as a general line of code that is of no interest if it doesn’t match one of the supported command types.
- #open? ⇒ Boolean
-
#values_array ⇒ Object
Returns an array containing the name / value pair for the command.
Constructor Details
#initialize(line: nil) ⇒ Command
Takes a line of code as a parameter and performs classification.
24 25 26 27 28 29 |
# File 'lib/confinicky/parsers/command.rb', line 24 def initialize(line: nil) @line = line @current_command_type = EXPORT_COMMAND if export? @current_command_type = ALIAS_COMMAND if alias? process_attributes! unless line? end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the command.
15 16 17 |
# File 'lib/confinicky/parsers/command.rb', line 15 def name @name end |
#value ⇒ Object (readonly)
The assigned value of the command.
19 20 21 |
# File 'lib/confinicky/parsers/command.rb', line 19 def value @value end |
Instance Method Details
#alias? ⇒ Boolean
Returns true if the line of code matches an alias command.
47 48 49 |
# File 'lib/confinicky/parsers/command.rb', line 47 def alias? matches_command_type?(ALIAS_COMMAND) && has_expression? end |
#append(value) ⇒ Object
66 67 68 |
# File 'lib/confinicky/parsers/command.rb', line 66 def append(value) @expression.append_value value end |
#closed? ⇒ Boolean
62 63 64 |
# File 'lib/confinicky/parsers/command.rb', line 62 def closed? !@expression.open? end |
#export? ⇒ Boolean
Returns true if the line of code matches an export command.
41 42 43 |
# File 'lib/confinicky/parsers/command.rb', line 41 def export? matches_command_type?(EXPORT_COMMAND) && has_expression? end |
#line? ⇒ Boolean
The command should be regarded as a general line of code that is of no interest if it doesn’t match one of the supported command types.
35 36 37 |
# File 'lib/confinicky/parsers/command.rb', line 35 def line? !export? && !alias? end |
#open? ⇒ Boolean
57 58 59 60 |
# File 'lib/confinicky/parsers/command.rb', line 57 def open? return false if line? || !has_expression? @expression.open? end |
#values_array ⇒ Object
Returns an array containing the name / value pair for the command.
53 54 55 |
# File 'lib/confinicky/parsers/command.rb', line 53 def values_array [@name, @expression.value] end |