class HalClient::Interpreter

Interprets parsed JSON

Constants

RESERVED_PROPERTIES

Collection of reserved properties tools.ietf.org/html/draft-kelly-json-hal-07#section-4.1

Attributes

hal_client[R]
raw[R]

Public Class Methods

new(parsed_json, hal_client) click to toggle source
# File lib/hal_client/interpreter.rb, line 16
def initialize(parsed_json, hal_client)
  (fail InvalidRepresentationError,
        "Invalid HAL representation: #{parsed_json.inspect}") unless
    hashish?(parsed_json)

  @raw = parsed_json
  @hal_client = hal_client
end

Public Instance Methods

extract_props() click to toggle source

Returns hash of properties from `parsed_json`

# File lib/hal_client/interpreter.rb, line 26
def extract_props()
  raw.reject{|k,_| RESERVED_PROPERTIES.include?(k) }
end

Protected Instance Methods

arrayify(obj) click to toggle source
# File lib/hal_client/interpreter.rb, line 134
def arrayify(obj)
  if Array === obj
    obj
  else
    [obj]
  end
end
curie_resolver() click to toggle source
# File lib/hal_client/interpreter.rb, line 125
def curie_resolver
  @curie_resolver ||= CurieResolver.new(raw.fetch("_links", {}).fetch("curies", []))
end
hashish?(obj) click to toggle source
# File lib/hal_client/interpreter.rb, line 38
def hashish?(obj)
  obj.respond_to?(:[]) &&
    obj.respond_to?(:map)
end
jpointer_esc(str) click to toggle source
# File lib/hal_client/interpreter.rb, line 142
def jpointer_esc(str)
  str.gsub "/", "~1"
end