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.



1096
1097
1098
1099
# File 'lib/carddb/collection.rb', line 1096

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



1094
1095
1096
# File 'lib/carddb/collection.rb', line 1094

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



1094
1095
1096
# File 'lib/carddb/collection.rb', line 1094

def data
  @data
end

Instance Method Details

#fieldObject



1101
1102
1103
# File 'lib/carddb/collection.rb', line 1101

def field
  data['field']
end


1105
1106
1107
# File 'lib/carddb/collection.rb', line 1105

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



1127
1128
1129
# File 'lib/carddb/collection.rb', line 1127

def record
  records.first
end

#recordsObject

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



1115
1116
1117
1118
1119
# File 'lib/carddb/collection.rb', line 1115

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)



1122
1123
1124
# File 'lib/carddb/collection.rb', line 1122

def value
  values.first
end

#valuesObject

Returns all values (always an array)



1110
1111
1112
# File 'lib/carddb/collection.rb', line 1110

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