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.



2314
2315
2316
2317
# File 'lib/carddb/collection.rb', line 2314

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2312
2313
2314
# File 'lib/carddb/collection.rb', line 2312

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



2312
2313
2314
# File 'lib/carddb/collection.rb', line 2312

def data
  @data
end

Instance Method Details

#fieldObject



2319
2320
2321
# File 'lib/carddb/collection.rb', line 2319

def field
  data['field']
end


2323
2324
2325
# File 'lib/carddb/collection.rb', line 2323

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



2345
2346
2347
# File 'lib/carddb/collection.rb', line 2345

def record
  records.first
end

#recordsObject

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



2333
2334
2335
2336
2337
# File 'lib/carddb/collection.rb', line 2333

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)



2340
2341
2342
# File 'lib/carddb/collection.rb', line 2340

def value
  values.first
end

#valuesObject

Returns all values (always an array)



2328
2329
2330
# File 'lib/carddb/collection.rb', line 2328

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