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.



2401
2402
2403
2404
# File 'lib/carddb/collection.rb', line 2401

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2399
2400
2401
# File 'lib/carddb/collection.rb', line 2399

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



2399
2400
2401
# File 'lib/carddb/collection.rb', line 2399

def data
  @data
end

Instance Method Details

#fieldObject



2406
2407
2408
# File 'lib/carddb/collection.rb', line 2406

def field
  data['field']
end


2410
2411
2412
# File 'lib/carddb/collection.rb', line 2410

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



2432
2433
2434
# File 'lib/carddb/collection.rb', line 2432

def record
  records.first
end

#recordsObject

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



2420
2421
2422
2423
2424
# File 'lib/carddb/collection.rb', line 2420

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)



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

def value
  values.first
end

#valuesObject

Returns all values (always an array)



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

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