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
#active_version_id ⇒ Object
471
472
473
|
# File 'lib/carddb/collection.rb', line 471
def active_version_id
data['activeVersionId']
end
|
#archived? ⇒ Boolean
483
484
485
|
# File 'lib/carddb/collection.rb', line 483
def archived?
data['isArchived']
end
|
#archived_at ⇒ Object
487
488
489
|
# File 'lib/carddb/collection.rb', line 487
def archived_at
parse_time(data['archivedAt'])
end
|
#created_at ⇒ Object
523
524
525
|
# File 'lib/carddb/collection.rb', line 523
def created_at
parse_time(data['createdAt'])
end
|
#description ⇒ Object
463
464
465
|
# File 'lib/carddb/collection.rb', line 463
def description
data['description']
end
|
#field(field_key) ⇒ FieldInfo?
Get a field’s info by key.
581
582
583
|
# File 'lib/carddb/collection.rb', line 581
def field(field_key)
schema&.field(field_key)
end
|
#field_keys ⇒ Array<String>
Get all field keys from the schema.
536
537
538
|
# File 'lib/carddb/collection.rb', line 536
def field_keys
schema&.fields&.map(&:key) || []
end
|
#filterable?(field_key) ⇒ Boolean
Check if a field is filterable.
565
566
567
|
# File 'lib/carddb/collection.rb', line 565
def filterable?(field_key)
filterable_fields.include?(field_key.to_s)
end
|
#filterable_fields ⇒ Array<String>
Get all filterable field keys.
543
544
545
|
# File 'lib/carddb/collection.rb', line 543
def filterable_fields
schema&.filterable_fields || []
end
|
#game ⇒ Object
515
516
517
|
# File 'lib/carddb/collection.rb', line 515
def game
data['game']
end
|
#game_id ⇒ Object
507
508
509
|
# File 'lib/carddb/collection.rb', line 507
def game_id
data['gameId']
end
|
#id ⇒ Object
451
452
453
|
# File 'lib/carddb/collection.rb', line 451
def id
data['id']
end
|
#identifier_field ⇒ String?
Get the identifier field key.
557
558
559
|
# File 'lib/carddb/collection.rb', line 557
def identifier_field
schema&.fields&.find(&:identifier?)&.key
end
|
#key ⇒ Object
455
456
457
|
# File 'lib/carddb/collection.rb', line 455
def key
data['key']
end
|
#name ⇒ Object
459
460
461
|
# File 'lib/carddb/collection.rb', line 459
def name
data['name']
end
|
#pos_x ⇒ Object
491
492
493
|
# File 'lib/carddb/collection.rb', line 491
def pos_x
data['posX']
end
|
#pos_y ⇒ Object
495
496
497
|
# File 'lib/carddb/collection.rb', line 495
def pos_y
data['posY']
end
|
#publisher ⇒ Object
511
512
513
|
# File 'lib/carddb/collection.rb', line 511
def publisher
data['publisher']
end
|
#publisher_id ⇒ Object
503
504
505
|
# File 'lib/carddb/collection.rb', line 503
def publisher_id
data['publisherId']
end
|
#purpose ⇒ Object
467
468
469
|
# File 'lib/carddb/collection.rb', line 467
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.
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
|
# File 'lib/carddb/collection.rb', line 594
def records(first: nil, filter: nil, include_pricing: false, &)
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,
&
)
end
|
#schema ⇒ Object
519
520
521
|
# File 'lib/carddb/collection.rb', line 519
def schema
@schema ||= DatasetSchema.new(data['schema']) if data['schema']
end
|
#searchable?(field_key) ⇒ Boolean
Check if a field is searchable.
573
574
575
|
# File 'lib/carddb/collection.rb', line 573
def searchable?(field_key)
searchable_fields.include?(field_key.to_s)
end
|
#searchable_fields ⇒ Array<String>
Get all searchable field keys.
550
551
552
|
# File 'lib/carddb/collection.rb', line 550
def searchable_fields
schema&.searchable_fields || []
end
|
#sort_order ⇒ Object
499
500
501
|
# File 'lib/carddb/collection.rb', line 499
def sort_order
data['sortOrder']
end
|
#tcgplayer_product_id_field_key ⇒ Object
475
476
477
|
# File 'lib/carddb/collection.rb', line 475
def tcgplayer_product_id_field_key
data['tcgplayerProductIdFieldKey']
end
|
#updated_at ⇒ Object
527
528
529
|
# File 'lib/carddb/collection.rb', line 527
def updated_at
parse_time(data['updatedAt'])
end
|
#visibility ⇒ Object
479
480
481
|
# File 'lib/carddb/collection.rb', line 479
def visibility
data['visibility']
end
|