Class: FDK::ParsedInput

Inherits:
Object
  • Object
show all
Defined in:
lib/fdk/support_classes.rb

Overview

ParsedInput stores raw input and can parse it as JSON (add extra formats as required)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_input:) ⇒ ParsedInput

Returns a new instance of ParsedInput.



25
26
27
# File 'lib/fdk/support_classes.rb', line 25

def initialize(raw_input:)
  @raw = raw_input
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



23
24
25
# File 'lib/fdk/support_classes.rb', line 23

def raw
  @raw
end

Instance Method Details

#as_jsonObject



29
30
31
32
33
# File 'lib/fdk/support_classes.rb', line 29

def as_json
  @json ||= JSON.parse(raw)
rescue JSON::ParserError
  @json = false
end

#parsedObject



35
36
37
# File 'lib/fdk/support_classes.rb', line 35

def parsed
  as_json || raw
end