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']


885
886
887
888
889
890
891
892
# File 'lib/carddb/collection.rb', line 885

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



876
877
878
# File 'lib/carddb/collection.rb', line 876

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

#created_atObject



864
865
866
# File 'lib/carddb/collection.rb', line 864

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

#datasetObject



852
853
854
# File 'lib/carddb/collection.rb', line 852

def dataset
  data['dataset']
end

#dataset_idObject



843
844
845
# File 'lib/carddb/collection.rb', line 843

def dataset_id
  data['datasetId']
end

#idObject



839
840
841
# File 'lib/carddb/collection.rb', line 839

def id
  data['id']
end

#pricingObject



860
861
862
# File 'lib/carddb/collection.rb', line 860

def pricing
  data['pricing']
end

#record_dataObject Also known as: fields



847
848
849
# File 'lib/carddb/collection.rb', line 847

def record_data
  data['data']
end


856
857
858
# File 'lib/carddb/collection.rb', line 856

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)


895
896
897
898
899
900
# File 'lib/carddb/collection.rb', line 895

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



868
869
870
# File 'lib/carddb/collection.rb', line 868

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