Class: Dcc::Convert::Result
- Inherits:
-
Object
- Object
- Dcc::Convert::Result
- Defined in:
- lib/dcc/convert/result.rb
Overview
Output of a Dcc::Convert::* converter. Carries the format and the
string payload. Outputs are models per the user's directive:
to_s returns the rendered payload, to_json / to_yaml return
the formatted payload directly.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#schema_version ⇒ Object
readonly
Returns the value of attribute schema_version.
-
#source_class ⇒ Object
readonly
Returns the value of attribute source_class.
Instance Method Summary collapse
-
#initialize(format:, payload:, source_class: nil, schema_version: nil) ⇒ Result
constructor
A new instance of Result.
-
#parsed ⇒ Object
Convenience: parse the payload back into Ruby data structures.
-
#to_json(*_args) ⇒ Object
Already-rendered JSON payload (not a re-render).
-
#to_s ⇒ Object
to_sreturns the rendered output. - #to_yaml(*_args) ⇒ Object
Constructor Details
#initialize(format:, payload:, source_class: nil, schema_version: nil) ⇒ Result
Returns a new instance of Result.
16 17 18 19 20 21 |
# File 'lib/dcc/convert/result.rb', line 16 def initialize(format:, payload:, source_class: nil, schema_version: nil) @format = format.to_sym @payload = payload.to_s @source_class = source_class @schema_version = schema_version end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/dcc/convert/result.rb', line 10 def format @format end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
10 11 12 |
# File 'lib/dcc/convert/result.rb', line 10 def payload @payload end |
#schema_version ⇒ Object (readonly)
Returns the value of attribute schema_version.
10 11 12 |
# File 'lib/dcc/convert/result.rb', line 10 def schema_version @schema_version end |
#source_class ⇒ Object (readonly)
Returns the value of attribute source_class.
10 11 12 |
# File 'lib/dcc/convert/result.rb', line 10 def source_class @source_class end |
Instance Method Details
#parsed ⇒ Object
Convenience: parse the payload back into Ruby data structures.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dcc/convert/result.rb', line 30 def parsed case @format when :json ::JSON.parse(@payload) when :yaml ::YAML.safe_load(@payload) else @payload end end |
#to_json(*_args) ⇒ Object
Already-rendered JSON payload (not a re-render).
42 43 44 |
# File 'lib/dcc/convert/result.rb', line 42 def to_json(*_args) @payload end |
#to_s ⇒ Object
to_s returns the rendered output.
24 25 26 |
# File 'lib/dcc/convert/result.rb', line 24 def to_s @payload end |
#to_yaml(*_args) ⇒ Object
46 47 48 |
# File 'lib/dcc/convert/result.rb', line 46 def to_yaml(*_args) @payload end |