Class: CardDB::Dataset
Overview
Wrapper for Dataset objects
Instance Attribute Summary
Attributes inherited from Resource
#client, #data
Instance Method Summary
collapse
Methods inherited from Resource
#[], #initialize, #key?, #to_h, #to_json
Instance Method Details
#archived? ⇒ Boolean
457
458
459
|
# File 'lib/carddb/collection.rb', line 457
def archived?
data['isArchived']
end
|
#created_at ⇒ Object
481
482
483
|
# File 'lib/carddb/collection.rb', line 481
def created_at
parse_time(data['createdAt'])
end
|
#description ⇒ Object
441
442
443
|
# File 'lib/carddb/collection.rb', line 441
def description
data['description']
end
|
#field(field_key) ⇒ FieldInfo?
Get a field’s info by key.
539
540
541
|
# File 'lib/carddb/collection.rb', line 539
def field(field_key)
schema&.field(field_key)
end
|
#field_keys ⇒ Array<String>
Get all field keys from the schema.
494
495
496
|
# File 'lib/carddb/collection.rb', line 494
def field_keys
schema&.fields&.map(&:key) || []
end
|
#filterable?(field_key) ⇒ Boolean
Check if a field is filterable.
523
524
525
|
# File 'lib/carddb/collection.rb', line 523
def filterable?(field_key)
filterable_fields.include?(field_key.to_s)
end
|
#filterable_fields ⇒ Array<String>
Get all filterable field keys.
501
502
503
|
# File 'lib/carddb/collection.rb', line 501
def filterable_fields
schema&.filterable_fields || []
end
|
#game ⇒ Object
473
474
475
|
# File 'lib/carddb/collection.rb', line 473
def game
data['game']
end
|
#game_id ⇒ Object
465
466
467
|
# File 'lib/carddb/collection.rb', line 465
def game_id
data['gameId']
end
|
#id ⇒ Object
429
430
431
|
# File 'lib/carddb/collection.rb', line 429
def id
data['id']
end
|
#identifier_field ⇒ String?
Get the identifier field key.
515
516
517
|
# File 'lib/carddb/collection.rb', line 515
def identifier_field
schema&.fields&.find(&:identifier?)&.key
end
|
#key ⇒ Object
433
434
435
|
# File 'lib/carddb/collection.rb', line 433
def key
data['key']
end
|
#name ⇒ Object
437
438
439
|
# File 'lib/carddb/collection.rb', line 437
def name
data['name']
end
|
#publisher ⇒ Object
469
470
471
|
# File 'lib/carddb/collection.rb', line 469
def publisher
data['publisher']
end
|
#publisher_id ⇒ Object
461
462
463
|
# File 'lib/carddb/collection.rb', line 461
def publisher_id
data['publisherId']
end
|
#purpose ⇒ Object
445
446
447
|
# File 'lib/carddb/collection.rb', line 445
def purpose
data['purpose']
end
|
#records(first: nil, filter: nil, include_pricing: false) {|FilterBuilder| ... } ⇒ Collection<Record>
Search records in this dataset. Unlike datasets on Game, this is NOT cached since filters can vary.
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
|
# File 'lib/carddb/collection.rb', line 552
def records(first: nil, filter: nil, include_pricing: false, &block)
raise Error, 'No client available to fetch records' unless client
publisher_slug = publisher&.[]('slug')
game_key = game&.[]('key')
raise Error, 'Publisher slug not available on this dataset' unless publisher_slug
raise Error, 'Game key not available on this dataset' unless game_key
client.records.search(
publisher_slug: publisher_slug,
game_key: game_key,
dataset_key: key,
first: first,
filter: filter,
include_pricing: include_pricing,
&block
)
end
|
#schema ⇒ Object
477
478
479
|
# File 'lib/carddb/collection.rb', line 477
def schema
@schema ||= DatasetSchema.new(data['schema']) if data['schema']
end
|
#searchable?(field_key) ⇒ Boolean
Check if a field is searchable.
531
532
533
|
# File 'lib/carddb/collection.rb', line 531
def searchable?(field_key)
searchable_fields.include?(field_key.to_s)
end
|
#searchable_fields ⇒ Array<String>
Get all searchable field keys.
508
509
510
|
# File 'lib/carddb/collection.rb', line 508
def searchable_fields
schema&.searchable_fields || []
end
|
#tcgplayer_product_id_field_key ⇒ Object
449
450
451
|
# File 'lib/carddb/collection.rb', line 449
def tcgplayer_product_id_field_key
data['tcgplayerProductIdFieldKey']
end
|
#updated_at ⇒ Object
485
486
487
|
# File 'lib/carddb/collection.rb', line 485
def updated_at
parse_time(data['updatedAt'])
end
|
#visibility ⇒ Object
453
454
455
|
# File 'lib/carddb/collection.rb', line 453
def visibility
data['visibility']
end
|