Class: CardDB::Resource
- Inherits:
-
Object
- Object
- CardDB::Resource
- Defined in:
- lib/carddb/collection.rb
Overview
Base class for resource wrappers
Instance Attribute Summary collapse
-
#client ⇒ Client?
readonly
The client instance for making related queries.
-
#data ⇒ Hash
readonly
The raw data from the API.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access raw data fields.
-
#initialize(data, client: nil) ⇒ Resource
constructor
A new instance of Resource.
-
#key?(key) ⇒ Boolean
Check if a field exists.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(data, client: nil) ⇒ Resource
Returns a new instance of Resource.
226 227 228 229 |
# File 'lib/carddb/collection.rb', line 226 def initialize(data, client: nil) @data = data || {} @client = client end |
Instance Attribute Details
#client ⇒ Client? (readonly)
Returns The client instance for making related queries.
224 225 226 |
# File 'lib/carddb/collection.rb', line 224 def client @client end |
#data ⇒ Hash (readonly)
Returns The raw data from the API.
221 222 223 |
# File 'lib/carddb/collection.rb', line 221 def data @data end |
Instance Method Details
#[](key) ⇒ Object
Access raw data fields
232 233 234 |
# File 'lib/carddb/collection.rb', line 232 def [](key) data[key.to_s] end |
#key?(key) ⇒ Boolean
Check if a field exists
237 238 239 |
# File 'lib/carddb/collection.rb', line 237 def key?(key) data.key?(key.to_s) end |
#to_h ⇒ Object
241 242 243 |
# File 'lib/carddb/collection.rb', line 241 def to_h data end |
#to_json(*args) ⇒ Object
245 246 247 |
# File 'lib/carddb/collection.rb', line 245 def to_json(*args) data.to_json(*args) end |