Class: K8s::JSONParser::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/k8s/json_parser.rb

Overview

Standard library JSON -based JSON-parsing backend

Defined Under Namespace

Classes: LineBufferedIO

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Default

Instantiate a streaming parser.

Examples:

result = []
parser = K8s::JSONParser::Default.new do |obj|
  result << obj
end
parser << '{"hello":"world"\n}'
parser << '{"hello":"world"\n}'
puts result.inspect
# outputs:
# [{ 'hello' => 'world' }, { 'hello' => 'world' }]


53
54
55
56
57
# File 'lib/k8s/json_parser.rb', line 53

def initialize(&block)
  @parser = LineBufferedIO.new do |data|
    block.call(JSON.parse(data))
  end
end

Class Method Details

.parse(input) ⇒ Hash, ...

Returns the parsed result.

Parameters:

  • input (String)

    JSON content

Returns:

  • (Hash, Array, String, Integer, Float, DateTime)

    the parsed result



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

def self.parse(input)
  JSON.parse(input)
end

Instance Method Details

#<<(data) ⇒ Object



59
60
61
# File 'lib/k8s/json_parser.rb', line 59

def <<(data)
  @parser << data
end