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.



2518
2519
2520
2521
# File 'lib/carddb/collection.rb', line 2518

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2516
2517
2518
# File 'lib/carddb/collection.rb', line 2516

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



2516
2517
2518
# File 'lib/carddb/collection.rb', line 2516

def data
  @data
end

Instance Method Details

#fieldObject



2523
2524
2525
# File 'lib/carddb/collection.rb', line 2523

def field
  data['field']
end


2527
2528
2529
# File 'lib/carddb/collection.rb', line 2527

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



2549
2550
2551
# File 'lib/carddb/collection.rb', line 2549

def record
  records.first
end

#recordsObject

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



2537
2538
2539
2540
2541
# File 'lib/carddb/collection.rb', line 2537

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)



2544
2545
2546
# File 'lib/carddb/collection.rb', line 2544

def value
  values.first
end

#valuesObject

Returns all values (always an array)



2532
2533
2534
# File 'lib/carddb/collection.rb', line 2532

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