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.



1600
1601
1602
1603
# File 'lib/carddb/collection.rb', line 1600

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



1598
1599
1600
# File 'lib/carddb/collection.rb', line 1598

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



1598
1599
1600
# File 'lib/carddb/collection.rb', line 1598

def data
  @data
end

Instance Method Details

#fieldObject



1605
1606
1607
# File 'lib/carddb/collection.rb', line 1605

def field
  data['field']
end


1609
1610
1611
# File 'lib/carddb/collection.rb', line 1609

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



1631
1632
1633
# File 'lib/carddb/collection.rb', line 1631

def record
  records.first
end

#recordsObject

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



1619
1620
1621
1622
1623
# File 'lib/carddb/collection.rb', line 1619

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)



1626
1627
1628
# File 'lib/carddb/collection.rb', line 1626

def value
  values.first
end

#valuesObject

Returns all values (always an array)



1614
1615
1616
# File 'lib/carddb/collection.rb', line 1614

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