Class: RFC8259::Value Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/RFC8259/value.rb

Overview

This class is abstract.

The Values, as described in RFC8259 section 3.

value = false / null / true / object / array / number / string

Direct Known Subclasses

Array, False, Null, Number, Object, String, True

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_ast(ast) ⇒ Value

Note:

the input MUST be a tree. No cyclic lists, nor even direct-acycric graphs are allowed by definition. Such input can cause undefined behaviour.

Parse the AST from parser, and convert into corrsponding values.

Parameters:

  • ast (::Array) —

    the AST, generated by the parser

Returns:

  • (Value) —

    evaluated instance

Raises:

  • (ArgumentError) —

    malformed input



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/RFC8259/value.rb', line 48

def self.from_ast ast
	klass = case ast.first
			  when :false  then RFC8259::False
			  when :null   then RFC8259::Null
			  when :true   then RFC8259::True
			  when :object then RFC8259::Object
			  when :array  then RFC8259::Array
			  when :number then RFC8259::Number
			  when :string then RFC8259::String
			  end
	return klass.from_ast ast
end

Instance Method Details

#inspect ⇒ ::String

Returns the class in string.

Returns:

  • (::String) —

    the class in string



67
68
69
# File 'lib/RFC8259/value.rb', line 67

def inspect
	sprintf "#<%p>", self.class
end

#plain_old_ruby_object ⇒ Object

convert to Ruby's value

Raises:

  • (RuntimeError)


62
63
64
# File 'lib/RFC8259/value.rb', line 62

def plain_old_ruby_object
	raise RuntimeError, 'abstruct method called'
end

#pretty_print(pp) ⇒ Object

For pretty print (require 'pp' beforehand)

Parameters:

  • pp (PP) —

    the pp



73
74
75
# File 'lib/RFC8259/value.rb', line 73

def pretty_print pp
	pp.object_group self do end # nothing
end