Module: HalInterpretation::ClassMethods

Defined in:
lib/hal_interpretation.rb

Instance Method Summary collapse

Instance Method Details

#extractor_for(attr_name) ⇒ Object

Returns the attribute extractor for the specified attribute.



130
131
132
# File 'lib/hal_interpretation.rb', line 130

def extractor_for(attr_name)
  extractors.find {|it| it.attr == attr_name }
end

#extractorsObject

Returns collection of attribute extractors.



125
126
127
# File 'lib/hal_interpretation.rb', line 125

def extractors
  @extractors ||= []
end

#new_from_json(json, opts = {}) ⇒ Object

Returns new interpreter for the provided JSON document.

Raises HalInterpretation::InvalidRepresentationError if the

provided JSON document is not parseable


114
115
116
117
118
119
120
# File 'lib/hal_interpretation.rb', line 114

def new_from_json(json, opts = {})
  repr = HalClient::Representation.new(parsed_json: MultiJson.load(json))
  self.new repr, opts.merge(location: "/")

rescue MultiJson::ParseError => err
  fail InvalidRepresentationError, "Parse error: " + err.message
end