Sha256: fdee6494ee9f95794b36d036ce88f6a5502a0513d7fdf8864ea8f2b5fed4349d

Contents?: true

Size: 813 Bytes

Versions: 7

Compression:

Stored size: 813 Bytes

Contents

require 'hyperclient/collection'

module Hyperclient
  # Public: A wrapper class to easily acces the attributes in a Resource.
  #
  # Examples
  #
  #   resource.attributes['title']
  #   resource.attributes.title
  #
  class Attributes < Collection
    RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/] # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1

    # Public: Initializes the Attributes of a Resource.
    #
    # representation - The hash with the HAL representation of the Resource.
    #
    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyperclient-0.8.1 lib/hyperclient/attributes.rb
hyperclient-0.8.0 lib/hyperclient/attributes.rb
hyperclient-0.7.2 lib/hyperclient/attributes.rb
hyperclient-0.7.1 lib/hyperclient/attributes.rb
hyperclient-0.7.0 lib/hyperclient/attributes.rb
hyperclient-0.6.1 lib/hyperclient/attributes.rb
hyperclient-0.5.0 lib/hyperclient/attributes.rb