Class: Hyperclient::Attributes

Inherits:
Collection show all
Defined in:
lib/hyperclient/attributes.rb

Overview

A wrapper class to easily acces the attributes in a Resource.

Examples:

resource.attributes['title']
resource.attributes.title

Constant Summary collapse

RESERVED_PROPERTIES =
[/^_links$/, /^_embedded$/].freeze

Instance Method Summary collapse

Methods inherited from Collection

#[], #each, #fetch, #include?, #method_missing, #respond_to_missing?, #to_h, #to_s

Constructor Details

#initialize(representation) ⇒ Attributes

Initializes the Attributes of a Resource.

Parameters:

  • representation

    The hash with the HAL representation of the Resource.



16
17
18
19
20
21
22
# File 'lib/hyperclient/attributes.rb', line 16

def initialize(representation)
  @collection = if representation.is_a?(Hash)
                  representation.delete_if { |key, _value| RESERVED_PROPERTIES.any? { |p| p.match(key) } }
                else
                  representation
                end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hyperclient::Collection