Class: Markie::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/markie/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, token_count:, children: [], value: nil) ⇒ Node

Returns a new instance of Node.



4
5
6
7
8
9
# File 'lib/markie/node.rb', line 4

def initialize(type:, token_count:, children: [], value: nil)
  @type = type
  @token_count = token_count
  @children = children
  @value = value
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



3
4
5
# File 'lib/markie/node.rb', line 3

def children
  @children
end

#token_countObject (readonly)

Returns the value of attribute token_count.



3
4
5
# File 'lib/markie/node.rb', line 3

def token_count
  @token_count
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/markie/node.rb', line 3

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/markie/node.rb', line 3

def value
  @value
end

Instance Method Details

#to_jsonObject



11
12
13
# File 'lib/markie/node.rb', line 11

def to_json
  "{ \"type\": \"#{type}\", \"token_count\": \"#{token_count}\", \"value\": \"#{value}\", \"children\": [#{children.map(&:to_json).join(", ") if children.any?}] }"
end