Class: Camp3::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/camp3/resource.rb

Direct Known Subclasses

Project

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Resource

Creates a new Resource object.



7
8
9
10
# File 'lib/camp3/resource.rb', line 7

def initialize(hash)
  @hash = hash
  @data = resourcify_data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

Respond to messages for which ‘self.data` has a key



58
59
60
# File 'lib/camp3/resource.rb', line 58

def method_missing(method_name, *args, &block)
  @data.key?(method_name.to_s) ? @data[method_name.to_s] : super
end

Instance Method Details

#[](key) ⇒ Object



23
24
25
# File 'lib/camp3/resource.rb', line 23

def [](key)
  data[key]
end

#can_be_commented?Boolean

Check whether a resource can be commented on or not given the presences of ‘comments_count` and `comments_url` keys

Returns:

  • (Boolean)


31
32
33
# File 'lib/camp3/resource.rb', line 31

def can_be_commented?
  hash.key?('comments_url') && hash.key?('comments_count')
end

#inspectString

Returns Formatted string with the class name, object id and original hash.

Returns:

  • (String)

    Formatted string with the class name, object id and original hash.



19
20
21
# File 'lib/camp3/resource.rb', line 19

def inspect
  "#<#{self.class}:#{object_id} {hash: #{hash.inspect}}"
end

#to_hashHash Also known as: to_h

Returns The original hash.

Returns:

  • (Hash)

    The original hash.



13
14
15
# File 'lib/camp3/resource.rb', line 13

def to_hash
  hash
end