Class: Fmt::Model

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin, Matchable
Defined in:
lib/fmt/models/model.rb

Overview

Note:

Models are constructed from AST nodes

Superclass for all models

Direct Known Subclasses

Arguments, Embed, Macro, Pipeline, Template

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#astObject (readonly)

: Node



22
23
24
# File 'lib/fmt/models/model.rb', line 22

def ast
  @ast
end

#sourceObject (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

#urtextObject (readonly)

: String – original source code



23
24
25
# File 'lib/fmt/models/model.rb', line 23

def urtext
  @urtext
end

Instance Method Details

#inspectObject

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

Returns:

  • (Boolean)


37
38
39
# File 'lib/fmt/models/model.rb', line 37

def self?(node)
  node == ast
end

#to_hObject

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