Class: Brandish::Parser::Node::Command
- Inherits:
-
Brandish::Parser::Node
- Object
- Brandish::Parser::Node
- Brandish::Parser::Node::Command
- Defined in:
- lib/brandish/parser/node/command.rb
Overview
A command node. This takes the form of {.a b=c}
, and executes a
given command with the given options.
Instance Attribute Summary collapse
-
#name ⇒ ::String
readonly
The name of the command node.
-
#pairs ⇒ {::String => ::String}
readonly
The "pairs" of arguments to be passed to the command.
Attributes inherited from Brandish::Parser::Node
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Determines if this object and the given object are equal.
-
#initialize(name:, arguments: nil, pairs: nil, location: nil) ⇒ Command
constructor
Initialize the command node.
-
#inspect ⇒ ::String
Pretty inspect.
Methods inherited from Brandish::Parser::Node
#prevent_update, #update, #update_prevented?
Constructor Details
#initialize(name: , arguments: , location: nil) ⇒ Command #initialize(name: , pairs: , location: ) ⇒ Command
Initialize the command node.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/brandish/parser/node/command.rb', line 43 def initialize(name:, arguments: nil, pairs: nil, location: nil) if !location && !arguments fail ArgumentError, "Expected either a location or " \ "arguments, got neither" end @name = name.is_a?(Yoga::Token) ? name.value : name.freeze @location = location || arguments.map(&:location) .inject(name.location, :union) @pairs = pairs.freeze || derive_pairs(arguments).freeze end |
Instance Attribute Details
#name ⇒ ::String (readonly)
The name of the command node. This is the name of the command that is executed.
14 15 16 |
# File 'lib/brandish/parser/node/command.rb', line 14 def name @name end |
#pairs ⇒ {::String => ::String} (readonly)
The "pairs" of arguments to be passed to the command.
19 20 21 |
# File 'lib/brandish/parser/node/command.rb', line 19 def pairs @pairs end |
Instance Method Details
#==(other) ⇒ Boolean
Determines if this object and the given object are equal. If the other object is this object, it returns true; otherwise, if the other object is a Brandish::Parser::Node::Command, and all of the properties of that object equal this one, then it returns true; otherwise, it returns false.
62 63 64 65 |
# File 'lib/brandish/parser/node/command.rb', line 62 def ==(other) equal?(other) || (other.is_a?(Command) && @name == other.name && @location == other.location && @pairs == other.pairs) end |
#inspect ⇒ ::String
Pretty inspect.
70 71 72 73 |
# File 'lib/brandish/parser/node/command.rb', line 70 def inspect "#<#{self.class} name=#{@name.inspect} pairs=#{@pairs.inspect} " \ "location=#{@location.inspect}>" end |