Class: CardDB::Dataset

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

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

Constructor Details

This class inherits a constructor from CardDB::Resource

Instance Method Details

#active_version_idObject



461
462
463
# File 'lib/carddb/collection.rb', line 461

def active_version_id
  data['activeVersionId']
end

#archived?Boolean

Returns:

  • (Boolean)


473
474
475
# File 'lib/carddb/collection.rb', line 473

def archived?
  data['isArchived']
end

#archived_atObject



477
478
479
# File 'lib/carddb/collection.rb', line 477

def archived_at
  parse_time(data['archivedAt'])
end

#created_atObject



513
514
515
# File 'lib/carddb/collection.rb', line 513

def created_at
  parse_time(data['createdAt'])
end

#descriptionObject



453
454
455
# File 'lib/carddb/collection.rb', line 453

def description
  data['description']
end

#field(field_key) ⇒ FieldInfo?

Get a field’s info by key.

Parameters:

  • field_key (String, Symbol)

    The field key

Returns:

  • (FieldInfo, nil)

    The field info or nil if not found



571
572
573
# File 'lib/carddb/collection.rb', line 571

def field(field_key)
  schema&.field(field_key)
end

#field_keysArray<String>

Get all field keys from the schema.

Returns:

  • (Array<String>)

    List of field keys



526
527
528
# File 'lib/carddb/collection.rb', line 526

def field_keys
  schema&.fields&.map(&:key) || []
end

#filterable?(field_key) ⇒ Boolean

Check if a field is filterable.

Parameters:

  • field_key (String, Symbol)

    The field key

Returns:

  • (Boolean)


555
556
557
# File 'lib/carddb/collection.rb', line 555

def filterable?(field_key)
  filterable_fields.include?(field_key.to_s)
end

#filterable_fieldsArray<String>

Get all filterable field keys.

Returns:

  • (Array<String>)

    List of filterable field keys



533
534
535
# File 'lib/carddb/collection.rb', line 533

def filterable_fields
  schema&.filterable_fields || []
end

#gameObject



505
506
507
# File 'lib/carddb/collection.rb', line 505

def game
  data['game']
end

#game_idObject



497
498
499
# File 'lib/carddb/collection.rb', line 497

def game_id
  data['gameId']
end

#idObject



441
442
443
# File 'lib/carddb/collection.rb', line 441

def id
  data['id']
end

#identifier_fieldString?

Get the identifier field key.

Returns:

  • (String, nil)

    The identifier field key or nil if none



547
548
549
# File 'lib/carddb/collection.rb', line 547

def identifier_field
  schema&.fields&.find(&:identifier?)&.key
end

#keyObject



445
446
447
# File 'lib/carddb/collection.rb', line 445

def key
  data['key']
end

#nameObject



449
450
451
# File 'lib/carddb/collection.rb', line 449

def name
  data['name']
end

#pos_xObject



481
482
483
# File 'lib/carddb/collection.rb', line 481

def pos_x
  data['posX']
end

#pos_yObject



485
486
487
# File 'lib/carddb/collection.rb', line 485

def pos_y
  data['posY']
end

#publisherObject



501
502
503
# File 'lib/carddb/collection.rb', line 501

def publisher
  data['publisher']
end

#publisher_idObject



493
494
495
# File 'lib/carddb/collection.rb', line 493

def publisher_id
  data['publisherId']
end

#purposeObject



457
458
459
# File 'lib/carddb/collection.rb', line 457

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.

Parameters:

  • first (Integer, nil) (defaults to: nil)

    Maximum number of results

  • filter (Hash, nil) (defaults to: nil)

    Filter conditions (alternative to block)

  • include_pricing (Boolean) (defaults to: false)

    Include live TCGPlayer pricing when configured

Yields:

Returns:

Raises:



584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/carddb/collection.rb', line 584

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

#schemaObject



509
510
511
# File 'lib/carddb/collection.rb', line 509

def schema
  @schema ||= DatasetSchema.new(data['schema']) if data['schema']
end

#searchable?(field_key) ⇒ Boolean

Check if a field is searchable.

Parameters:

  • field_key (String, Symbol)

    The field key

Returns:

  • (Boolean)


563
564
565
# File 'lib/carddb/collection.rb', line 563

def searchable?(field_key)
  searchable_fields.include?(field_key.to_s)
end

#searchable_fieldsArray<String>

Get all searchable field keys.

Returns:

  • (Array<String>)

    List of searchable field keys



540
541
542
# File 'lib/carddb/collection.rb', line 540

def searchable_fields
  schema&.searchable_fields || []
end

#sort_orderObject



489
490
491
# File 'lib/carddb/collection.rb', line 489

def sort_order
  data['sortOrder']
end

#tcgplayer_product_id_field_keyObject



465
466
467
# File 'lib/carddb/collection.rb', line 465

def tcgplayer_product_id_field_key
  data['tcgplayerProductIdFieldKey']
end

#updated_atObject



517
518
519
# File 'lib/carddb/collection.rb', line 517

def updated_at
  parse_time(data['updatedAt'])
end

#visibilityObject



469
470
471
# File 'lib/carddb/collection.rb', line 469

def visibility
  data['visibility']
end