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.



884
885
886
887
# File 'lib/carddb/collection.rb', line 884

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



882
883
884
# File 'lib/carddb/collection.rb', line 882

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



882
883
884
# File 'lib/carddb/collection.rb', line 882

def data
  @data
end

Instance Method Details

#fieldObject



889
890
891
# File 'lib/carddb/collection.rb', line 889

def field
  data['field']
end


893
894
895
# File 'lib/carddb/collection.rb', line 893

def link_field_key
  data['linkFieldKey']
end

#recordObject

Convenience: first record (for single-link fields)



915
916
917
# File 'lib/carddb/collection.rb', line 915

def record
  records.first
end

#recordsObject

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



903
904
905
906
907
# File 'lib/carddb/collection.rb', line 903

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)



910
911
912
# File 'lib/carddb/collection.rb', line 910

def value
  values.first
end

#valuesObject

Returns all values (always an array)



898
899
900
# File 'lib/carddb/collection.rb', line 898

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