Class: CardDB::ResolvedLink

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

Overview

Wrapper for ResolvedLink Supports both single links and arrays of links

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, client: nil) ⇒ ResolvedLink

Returns a new instance of ResolvedLink.



2414
2415
2416
2417
# File 'lib/carddb/collection.rb', line 2414

def initialize(data, client: nil)
  @data = data || {}
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2412
2413
2414
# File 'lib/carddb/collection.rb', line 2412

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



2412
2413
2414
# File 'lib/carddb/collection.rb', line 2412

def data
  @data
end

Instance Method Details

#fieldObject



2419
2420
2421
# File 'lib/carddb/collection.rb', line 2419

def field
  data['field']
end


2423
2424
2425
# File 'lib/carddb/collection.rb', line 2423

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



2445
2446
2447
# File 'lib/carddb/collection.rb', line 2445

def record
  records.first
end

#recordsObject

Returns all resolved records (parallel array to values, nil for unresolved)



2433
2434
2435
2436
2437
# File 'lib/carddb/collection.rb', line 2433

def records
  @records ||= (data['records'] || []).map do |rec|
    rec ? Record.new(rec, client: client) : nil
  end
end

#valueObject

Convenience: first value (for single-link fields)



2440
2441
2442
# File 'lib/carddb/collection.rb', line 2440

def value
  values.first
end

#valuesObject

Returns all values (always an array)



2428
2429
2430
# File 'lib/carddb/collection.rb', line 2428

def values
  data['values'] || []
end