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.



2117
2118
2119
2120
# File 'lib/carddb/collection.rb', line 2117

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2115
2116
2117
# File 'lib/carddb/collection.rb', line 2115

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



2115
2116
2117
# File 'lib/carddb/collection.rb', line 2115

def data
  @data
end

Instance Method Details

#fieldObject



2122
2123
2124
# File 'lib/carddb/collection.rb', line 2122

def field
  data['field']
end


2126
2127
2128
# File 'lib/carddb/collection.rb', line 2126

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



2148
2149
2150
# File 'lib/carddb/collection.rb', line 2148

def record
  records.first
end

#recordsObject

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



2136
2137
2138
2139
2140
# File 'lib/carddb/collection.rb', line 2136

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)



2143
2144
2145
# File 'lib/carddb/collection.rb', line 2143

def value
  values.first
end

#valuesObject

Returns all values (always an array)



2131
2132
2133
# File 'lib/carddb/collection.rb', line 2131

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