Class: CardDB::Record

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

Overview

Wrapper for DatasetRecord 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Access record data fields directly via method calls

Examples:

record.name  # equivalent to record['name']
record.hp    # equivalent to record['hp']


751
752
753
754
755
756
757
758
# File 'lib/carddb/collection.rb', line 751

def method_missing(method_name, *args, &block)
  key = method_name.to_s

  # Only handle reader methods (no args, no block, no assignment)
  return record_data&.[](key) if args.empty? && block.nil? && !key.end_with?('=')

  super
end

Instance Method Details

#[](key) ⇒ Object?

Access record data fields directly via bracket notation

Parameters:

  • key (String, Symbol)

    The field name

Returns:

  • (Object, nil)

    The field value



742
743
744
# File 'lib/carddb/collection.rb', line 742

def [](key)
  record_data&.[](key.to_s)
end

#created_atObject



730
731
732
# File 'lib/carddb/collection.rb', line 730

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

#datasetObject



718
719
720
# File 'lib/carddb/collection.rb', line 718

def dataset
  data['dataset']
end

#dataset_idObject



709
710
711
# File 'lib/carddb/collection.rb', line 709

def dataset_id
  data['datasetId']
end

#idObject



705
706
707
# File 'lib/carddb/collection.rb', line 705

def id
  data['id']
end

#pricingObject



726
727
728
# File 'lib/carddb/collection.rb', line 726

def pricing
  data['pricing']
end

#record_dataObject Also known as: fields



713
714
715
# File 'lib/carddb/collection.rb', line 713

def record_data
  data['data']
end


722
723
724
# File 'lib/carddb/collection.rb', line 722

def resolved_links
  @resolved_links ||= parse_resolved_links
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Support respond_to? for dynamic field access

Returns:

  • (Boolean)


761
762
763
764
765
766
# File 'lib/carddb/collection.rb', line 761

def respond_to_missing?(method_name, include_private = false)
  key = method_name.to_s
  return true if record_data&.key?(key)

  super
end

#updated_atObject



734
735
736
# File 'lib/carddb/collection.rb', line 734

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