Module: OEmbed::Formatter::JSON::Backends::Yaml

Extended by:
Yaml
Included in:
Yaml
Defined in:
lib/oembed/formatter/json/backends/yaml.rb

Overview

Use the YAML library, part of the standard library, to parse JSON values that has been converted to YAML.

Instance Method Summary collapse

Instance Method Details

#decode(json) ⇒ Object

Parses a JSON string or IO and converts it into an object.



13
14
15
16
17
18
19
20
# File 'lib/oembed/formatter/json/backends/yaml.rb', line 13

def decode(json)
  if json.respond_to?(:read)
    json = json.read
  end
  YAML.load(convert_json_to_yaml(json))
rescue ArgumentError, Psych::SyntaxError
  raise parse_error, "Invalid JSON string"
end

#decode_fail_msgObject



22
23
24
# File 'lib/oembed/formatter/json/backends/yaml.rb', line 22

def decode_fail_msg
  "The version of the YAML library you have installed isn't parsing JSON like ruby-oembed expected."
end

#parse_errorObject



26
27
28
# File 'lib/oembed/formatter/json/backends/yaml.rb', line 26

def parse_error
  ::StandardError
end