Class: Camper::Resource
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#can_be_commented? ⇒ Boolean
Check whether a resource can be commented on or not given the presences of ‘comments_count` and `comments_url` keys.
-
#initialize(hash) ⇒ Resource
constructor
Creates a new Resource object.
-
#inspect ⇒ String
Formatted string with the class name, object id and original hash.
-
#to_hash ⇒ Hash
(also: #to_h)
The original hash.
Constructor Details
#initialize(hash) ⇒ Resource
Creates a new Resource object.
7 8 9 10 |
# File 'lib/camper/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
62 63 64 |
# File 'lib/camper/resource.rb', line 62 def method_missing(method_name, *args, &block) @data.key?(method_name.to_s) ? @data[method_name.to_s] : super end |
Class Method Details
.create(hash) ⇒ Object
35 36 37 38 39 |
# File 'lib/camper/resource.rb', line 35 def self.create(hash) klass = detect_type(hash["url"]) return klass.new(hash) end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 |
# File 'lib/camper/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
31 32 33 |
# File 'lib/camper/resource.rb', line 31 def can_be_commented? hash.key?('comments_url') && hash.key?('comments_count') end |
#inspect ⇒ String
Returns Formatted string with the class name, object id and original hash.
19 20 21 |
# File 'lib/camper/resource.rb', line 19 def inspect "#<#{self.class}:#{object_id} {hash: #{hash.inspect}}" end |
#to_hash ⇒ Hash Also known as: to_h
Returns The original hash.
13 14 15 |
# File 'lib/camper/resource.rb', line 13 def to_hash hash end |