Module: Hatena::Bookmark::Restful::V1::ResponseObject

Included in:
Bookmark, Entry, Tag, User
Defined in:
lib/hatena/bookmark/restful/v1/response_object.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(context) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/hatena/bookmark/restful/v1/response_object.rb', line 21

def self.included(context)
  properties = context.const_get(:PROPERTIES)
  context.send(:extend, ClassMethods)
  properties.each do |prop|
    define_method(prop) { @attributes.fetch(prop) }
  end
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/hatena/bookmark/restful/v1/response_object.rb', line 40

def ==(other)
  other.is_a?(self.class) && self.class.const_get(:PROPERTIES).all? {|prop| self[prop] == other[prop] }
end

#[](name) ⇒ Object

Fetch raw attribute value

Parameters:

  • name (Symbol)

    The attribute’s name



35
36
37
# File 'lib/hatena/bookmark/restful/v1/response_object.rb', line 35

def [](name)
  @attributes[name]
end

#initialize(attributes) ⇒ Object



29
30
31
# File 'lib/hatena/bookmark/restful/v1/response_object.rb', line 29

def initialize(attributes)
  @attributes = attributes
end

#to_hashHash

Returns:

  • (Hash)


45
46
47
# File 'lib/hatena/bookmark/restful/v1/response_object.rb', line 45

def to_hash
  @attributes
end