Class: Acv2lrtemplate::JSON2lrtemplate
- Defined in:
- lib/acv2lrtemplate/json2lrtemplate.rb
Instance Attribute Summary collapse
-
#json_string ⇒ Object
readonly
Returns the value of attribute json_string.
Instance Method Summary collapse
-
#convert! ⇒ Object
Transform “keys” to keys Transform [] to {} - works for values on the same line? Transform : to = Remove leading and ending {} , before closing }.
-
#initialize(json_string) ⇒ JSON2lrtemplate
constructor
A new instance of JSON2lrtemplate.
Constructor Details
#initialize(json_string) ⇒ JSON2lrtemplate
Returns a new instance of JSON2lrtemplate.
7 8 9 |
# File 'lib/acv2lrtemplate/json2lrtemplate.rb', line 7 def initialize(json_string) @json_string = json_string end |
Instance Attribute Details
#json_string ⇒ Object (readonly)
Returns the value of attribute json_string.
5 6 7 |
# File 'lib/acv2lrtemplate/json2lrtemplate.rb', line 5 def json_string @json_string end |
Instance Method Details
#convert! ⇒ Object
Transform “keys” to keys Transform [] to {} - works for values on the same line? Transform : to = Remove leading and ending {} , before closing }
17 18 19 20 21 22 23 |
# File 'lib/acv2lrtemplate/json2lrtemplate.rb', line 17 def convert! @json_string.gsub(/"(\w+)"(?=:)/) { |_| $1.camelize(false) } .gsub(/(\[[.\S\s^"]*?\])/) { |_| $1.tr('[]', '{}') } .gsub(':', ' = ') .sub(/\A{/, '').sub(/}\Z/, '') .gsub(/(?<=.)(}){1}(?=.)?/) { |_| ",#{$1}" } end |