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.



7
8
9
# File 'lib/fdk/support_classes.rb', line 7

def initialize(raw_input:)
  @raw = raw_input
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



5
6
7
# File 'lib/fdk/support_classes.rb', line 5

def raw
  @raw
end

Instance Method Details

#as_jsonObject



11
12
13
14
15
# File 'lib/fdk/support_classes.rb', line 11

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

#parsedObject



17
18
19
# File 'lib/fdk/support_classes.rb', line 17

def parsed
  as_json || raw
end