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.



85
86
87
# File 'lib/hal_interpretation.rb', line 85

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

#extractorsObject

Returns collection of attribute extractors.



80
81
82
# File 'lib/hal_interpretation.rb', line 80

def extractors
  @extractors ||= []
end

#new_from_json(json) ⇒ Object

Returns new interpreter for the provided JSON document.

Raises HalInterpretation::InvalidRepresentationError if the

provided JSON document is not parseable


69
70
71
72
73
74
75
# File 'lib/hal_interpretation.rb', line 69

def new_from_json(json)
  self.new HalClient::Representation.new(parsed_json: MultiJson.load(json)),
           location: "/"

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