Class: Slamdown::Parsing::Node
- Inherits:
-
Object
- Object
- Slamdown::Parsing::Node
- Defined in:
- lib/slamdown/parsing/node.rb
Overview
Immutable, format-neutral representation of one parsed construct. It contains parser facts only; element policy, structural correction and rendering belong to later stages.
Constant Summary collapse
- ATTRIBUTES =
[ :kind, :source_name, :semantic_kind, :category, :content_model, :value, :attributes, :children, :properties, :source_form, :synthetic ].freeze
Instance Method Summary collapse
-
#initialize(kind:, source_name: nil, semantic_kind: nil, category: nil, content_model: nil, value: nil, attributes: [], children: [], properties: {}, source_form: nil, synthetic: false) ⇒ Node
constructor
A new instance of Node.
-
#to_h ⇒ Object
Provides a stable plain-Ruby projection for diagnostics and characterisation.
Constructor Details
#initialize(kind:, source_name: nil, semantic_kind: nil, category: nil, content_model: nil, value: nil, attributes: [], children: [], properties: {}, source_form: nil, synthetic: false) ⇒ Node
Returns a new instance of Node.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/slamdown/parsing/node.rb', line 24 def initialize(kind:, source_name: nil, semantic_kind: nil, category: nil, content_model: nil, value: nil, attributes: [], children: [], properties: {}, source_form: nil, synthetic: false) @kind = kind @source_name = Immutable.copy(source_name) @semantic_kind = semantic_kind @category = category @content_model = content_model @value = Immutable.copy(value) @attributes = Immutable.copy(attributes) @children = children.dup.freeze @properties = Immutable.copy(properties) @source_form = Immutable.copy(source_form) @synthetic = synthetic freeze end |
Instance Method Details
#to_h ⇒ Object
Provides a stable plain-Ruby projection for diagnostics and characterisation.
40 41 42 43 44 45 |
# File 'lib/slamdown/parsing/node.rb', line 40 def to_h ATTRIBUTES.each_with_object({}) do |attribute, result| value = public_send(attribute) result[attribute] = attribute == :children ? value.map(&:to_h) : value end end |