Class: Brandish::Parser::Node::Block
- Inherits:
-
Brandish::Parser::Node
- Object
- Brandish::Parser::Node
- Brandish::Parser::Node::Block
- Defined in:
- lib/brandish/parser/node/block.rb
Overview
A "block" node. Basically, this is a node that encapsulates a block of text. This typically has a 1-to-1 relationship with the body of text, while a command may not.
Instance Attribute Summary collapse
-
#body ⇒ Node::Root
readonly
The body of the block.
-
#name ⇒ ::String
readonly
The name of the block.
-
#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
Equates this object with another object.
-
#initialize(name:, body:, arguments: nil, pairs: nil, location: nil) ⇒ Block
constructor
A new instance of Block.
-
#inspect ⇒ ::String
Pretty inspect.
Methods inherited from Brandish::Parser::Node
#prevent_update, #update, #update_prevented?
Constructor Details
#initialize(name:, body:, arguments: nil, pairs: nil, location: nil) ⇒ Block
Returns a new instance of Block.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/brandish/parser/node/block.rb', line 33 def initialize(name:, body:, 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 @body = body @location = location || arguments.map(&:location) .inject(name.location.union(body.location), :union) @pairs = pairs.freeze || derive_pairs(arguments).freeze end |
Instance Attribute Details
#body ⇒ Node::Root (readonly)
The body of the block.
19 20 21 |
# File 'lib/brandish/parser/node/block.rb', line 19 def body @body end |
#name ⇒ ::String (readonly)
The name of the block.
14 15 16 |
# File 'lib/brandish/parser/node/block.rb', line 14 def name @name end |
#pairs ⇒ {::String => ::String} (readonly)
The "pairs" of arguments to be passed to the command.
24 25 26 |
# File 'lib/brandish/parser/node/block.rb', line 24 def pairs @pairs end |
Instance Method Details
#==(other) ⇒ Boolean
Equates this object with another object. If the other object is this object, it returns true; otherwise, if it is a block, whose properties all equal this one, it returns true; otherwise, it returns false.
62 63 64 65 |
# File 'lib/brandish/parser/node/block.rb', line 62 def ==(other) equal?(other) || other.is_a?(Block) && @name == other.name && @body == other.body && @location == other.location end |
#inspect ⇒ ::String
Pretty inspect.
50 51 52 53 |
# File 'lib/brandish/parser/node/block.rb', line 50 def inspect "#<#{self.class} name=#{@name.inspect} pairs=#{@pairs.inspect} " \ "body=#{@body.inspect} location=#{@location.inspect}>" end |