Class: Camp3::Resource
- Inherits:
-
Object
- Object
- Camp3::Resource
- Defined in:
- lib/camp3/resource.rb
Direct Known Subclasses
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/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
31 32 33 |
# File 'lib/camp3/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/camp3/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/camp3/resource.rb', line 13 def to_hash hash end |