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.



2475
2476
2477
2478
# File 'lib/carddb/collection.rb', line 2475

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2473
2474
2475
# File 'lib/carddb/collection.rb', line 2473

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



2473
2474
2475
# File 'lib/carddb/collection.rb', line 2473

def data
  @data
end

Instance Method Details

#fieldObject



2480
2481
2482
# File 'lib/carddb/collection.rb', line 2480

def field
  data['field']
end


2484
2485
2486
# File 'lib/carddb/collection.rb', line 2484

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



2506
2507
2508
# File 'lib/carddb/collection.rb', line 2506

def record
  records.first
end

#recordsObject

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



2494
2495
2496
2497
2498
# File 'lib/carddb/collection.rb', line 2494

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)



2501
2502
2503
# File 'lib/carddb/collection.rb', line 2501

def value
  values.first
end

#valuesObject

Returns all values (always an array)



2489
2490
2491
# File 'lib/carddb/collection.rb', line 2489

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