Class: Hash2lrtemplate::JSON2lrtemplate

Inherits:
Object
  • Object
show all
Includes:
CallableClass
Defined in:
lib/hash2lrtemplate/json2lrtemplate.rb

Overview

Transformations:

  • Transform “keys” to keys (remove quotes)

  • Transform [] to {}

  • Transform : to =

  • Remove leading and ending {}

  • , before closing }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_string) ⇒ JSON2lrtemplate

Returns a new instance of JSON2lrtemplate.



16
17
18
19
20
# File 'lib/hash2lrtemplate/json2lrtemplate.rb', line 16

def initialize(json_string)
  raise Hash2lrtemplate::Error, 'Invalid class. Expected class: `String`' unless json_string.is_a?(String)

  @json_string = json_string
end

Instance Attribute Details

#json_stringObject (readonly)

Returns the value of attribute json_string.



14
15
16
# File 'lib/hash2lrtemplate/json2lrtemplate.rb', line 14

def json_string
  @json_string
end

Instance Method Details

#callString

Convert from JSON to .lrtemplate format

Returns:

  • (String)

    Converted string



27
28
29
# File 'lib/hash2lrtemplate/json2lrtemplate.rb', line 27

def call
  convert
end