Class: Fmt::Model
- Inherits:
-
Object
- Object
- Fmt::Model
- Includes:
- AST::Processor::Mixin, Matchable
- Defined in:
- lib/fmt/models/model.rb
Overview
Note:
Models are constructed from AST nodes
Superclass for all models
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
: Node.
-
#source ⇒ Object
(also: #to_s)
readonly
: String – parsed source code.
-
#urtext ⇒ Object
readonly
: String – original source code.
Instance Method Summary collapse
-
#initialize(ast) ⇒ Model
constructor
Constructor.
-
#inspect ⇒ Object
Model inspection.
-
#self?(node) ⇒ Boolean
Indicates if a given AST node is the same AST used to construct the model.
-
#to_h ⇒ Object
Hash representation of the model (required for pattern matching).
Methods included from Matchable
#deconstruct, #deconstruct_keys
Constructor Details
#initialize(ast) ⇒ Model
Constructor
15 16 17 18 19 20 |
# File 'lib/fmt/models/model.rb', line 15 def initialize(ast) @ast = ast @urtext = ast.urtext @source = ast.source process ast end |
Instance Attribute Details
#ast ⇒ Object (readonly)
: Node
22 23 24 |
# File 'lib/fmt/models/model.rb', line 22 def ast @ast end |
#source ⇒ Object (readonly) Also known as: to_s
: String – parsed source code
24 25 26 |
# File 'lib/fmt/models/model.rb', line 24 def source @source end |
#urtext ⇒ Object (readonly)
: String – original source code
23 24 25 |
# File 'lib/fmt/models/model.rb', line 23 def urtext @urtext end |
Instance Method Details
#inspect ⇒ Object
Model inspection
30 31 32 |
# File 'lib/fmt/models/model.rb', line 30 def inspect "#<#{self.class.name} #{inspect_properties}>" end |
#self?(node) ⇒ Boolean
Indicates if a given AST node is the same AST used to construct the model
37 38 39 |
# File 'lib/fmt/models/model.rb', line 37 def self?(node) node == ast end |
#to_h ⇒ Object
Note:
Subclasses should override this method and call: super.merge(**)
Hash representation of the model (required for pattern matching)
44 45 46 |
# File 'lib/fmt/models/model.rb', line 44 def to_h {} end |