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

#archived?Boolean

Returns:

  • (Boolean)


443
444
445
# File 'lib/carddb/collection.rb', line 443

def archived?
  data['isArchived']
end

#created_atObject



467
468
469
# File 'lib/carddb/collection.rb', line 467

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

#descriptionObject



431
432
433
# File 'lib/carddb/collection.rb', line 431

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



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

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



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

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)


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

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



487
488
489
# File 'lib/carddb/collection.rb', line 487

def filterable_fields
  schema&.filterable_fields || []
end

#gameObject



459
460
461
# File 'lib/carddb/collection.rb', line 459

def game
  data['game']
end

#game_idObject



451
452
453
# File 'lib/carddb/collection.rb', line 451

def game_id
  data['gameId']
end

#idObject



419
420
421
# File 'lib/carddb/collection.rb', line 419

def id
  data['id']
end

#identifier_fieldString?

Get the identifier field key.

Returns:

  • (String, nil)

    The identifier field key or nil if none



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

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

#keyObject



423
424
425
# File 'lib/carddb/collection.rb', line 423

def key
  data['key']
end

#nameObject



427
428
429
# File 'lib/carddb/collection.rb', line 427

def name
  data['name']
end

#publisherObject



455
456
457
# File 'lib/carddb/collection.rb', line 455

def publisher
  data['publisher']
end

#publisher_idObject



447
448
449
# File 'lib/carddb/collection.rb', line 447

def publisher_id
  data['publisherId']
end

#purposeObject



435
436
437
# File 'lib/carddb/collection.rb', line 435

def purpose
  data['purpose']
end

#records(first: nil, filter: nil) {|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)

Yields:

Returns:

Raises:



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/carddb/collection.rb', line 537

def records(first: nil, filter: nil, &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,
    &block
  )
end

#schemaObject



463
464
465
# File 'lib/carddb/collection.rb', line 463

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)


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

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



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

def searchable_fields
  schema&.searchable_fields || []
end

#updated_atObject



471
472
473
# File 'lib/carddb/collection.rb', line 471

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

#visibilityObject



439
440
441
# File 'lib/carddb/collection.rb', line 439

def visibility
  data['visibility']
end