Class: CardDB::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/carddb/collection.rb

Overview

Base class for resource wrappers

Direct Known Subclasses

Dataset, Deck, DeckEntry, Game, Publisher, Record

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientClient? (readonly)

Returns The client instance for making related queries.

Returns:

  • (Client, nil)

    The client instance for making related queries



224
225
226
# File 'lib/carddb/collection.rb', line 224

def client
  @client
end

#dataHash (readonly)

Returns The raw data from the API.

Returns:

  • (Hash)

    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

Returns:

  • (Boolean)


237
238
239
# File 'lib/carddb/collection.rb', line 237

def key?(key)
  data.key?(key.to_s)
end

#to_hObject



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