Class: JSON5::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/json5/document_nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, source:, start_byte:, end_byte:, leading_trivia: [], trailing_trivia: []) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
14
15
16
17
18
# File 'lib/json5/document_nodes.rb', line 9

def initialize(type:, source:, start_byte:, end_byte:, leading_trivia: [], trailing_trivia: [])
  @type = type.to_sym
  @source = source
  @start_byte = start_byte
  @end_byte = end_byte
  @raw_span = ByteSpan.new(start_byte, end_byte)
  @leading_trivia = leading_trivia.dup.freeze
  @trailing_trivia = trailing_trivia.dup.freeze
  freeze
end

Instance Attribute Details

#end_byteObject (readonly)

Returns the value of attribute end_byte.



7
8
9
# File 'lib/json5/document_nodes.rb', line 7

def end_byte
  @end_byte
end

#leading_triviaObject (readonly)

Returns the value of attribute leading_trivia.



7
8
9
# File 'lib/json5/document_nodes.rb', line 7

def leading_trivia
  @leading_trivia
end

#raw_spanObject (readonly)

Returns the value of attribute raw_span.



7
8
9
# File 'lib/json5/document_nodes.rb', line 7

def raw_span
  @raw_span
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/json5/document_nodes.rb', line 7

def source
  @source
end

#start_byteObject (readonly)

Returns the value of attribute start_byte.



7
8
9
# File 'lib/json5/document_nodes.rb', line 7

def start_byte
  @start_byte
end

#trailing_triviaObject (readonly)

Returns the value of attribute trailing_trivia.



7
8
9
# File 'lib/json5/document_nodes.rb', line 7

def trailing_trivia
  @trailing_trivia
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/json5/document_nodes.rb', line 7

def type
  @type
end

Instance Method Details

#rawObject



20
21
22
# File 'lib/json5/document_nodes.rb', line 20

def raw
  source.byteslice(start_byte...end_byte)
end