Class: Krikri::JsonParser::Value

Inherits:
Parser::Value show all
Defined in:
lib/krikri/parsers/json_parser.rb

Overview

JsonParser::Value

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser::Value

#[], #attribute?, #child?, #method_missing, #respond_to_missing

Constructor Details

#initialize(node) ⇒ Value

Returns a new instance of Value.



25
26
27
# File 'lib/krikri/parsers/json_parser.rb', line 25

def initialize(node)
  @node = node
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Krikri::Parser::Value

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



23
24
25
# File 'lib/krikri/parsers/json_parser.rb', line 23

def node
  @node
end

Instance Method Details

#attributesObject

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/krikri/parsers/json_parser.rb', line 29

def attributes
  raise NotImplementedError, 'Attributes are not supported for JSON'
end

#childrenObject



33
34
35
# File 'lib/krikri/parsers/json_parser.rb', line 33

def children
  @node.is_a?(Hash) ? @node.keys : []
end

#valueObject



37
38
39
# File 'lib/krikri/parsers/json_parser.rb', line 37

def value
  @node.is_a?(Hash) ? @node.to_s : @node
end

#values?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/krikri/parsers/json_parser.rb', line 41

def values?
  !select_values.empty?
end