Class: CardDB::ResolvedLink
- Inherits:
-
Object
- Object
- CardDB::ResolvedLink
- Defined in:
- lib/carddb/collection.rb
Overview
Wrapper for ResolvedLink Supports both single links and arrays of links
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #field ⇒ Object
-
#initialize(data, client: nil) ⇒ ResolvedLink
constructor
A new instance of ResolvedLink.
- #link_field_key ⇒ Object
-
#record ⇒ Object
Convenience: first record (for single-link fields).
-
#records ⇒ Object
Returns all resolved records (parallel array to values, nil for unresolved).
-
#value ⇒ Object
Convenience: first value (for single-link fields).
-
#values ⇒ Object
Returns all values (always an array).
Constructor Details
#initialize(data, client: nil) ⇒ ResolvedLink
Returns a new instance of ResolvedLink.
1086 1087 1088 1089 |
# File 'lib/carddb/collection.rb', line 1086 def initialize(data, client: nil) @data = data || {} @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
1084 1085 1086 |
# File 'lib/carddb/collection.rb', line 1084 def client @client end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
1084 1085 1086 |
# File 'lib/carddb/collection.rb', line 1084 def data @data end |
Instance Method Details
#field ⇒ Object
1091 1092 1093 |
# File 'lib/carddb/collection.rb', line 1091 def field data['field'] end |
#link_field_key ⇒ Object
1095 1096 1097 |
# File 'lib/carddb/collection.rb', line 1095 def link_field_key data['linkFieldKey'] end |
#record ⇒ Object
Convenience: first record (for single-link fields)
1117 1118 1119 |
# File 'lib/carddb/collection.rb', line 1117 def record records.first end |
#records ⇒ Object
Returns all resolved records (parallel array to values, nil for unresolved)
1105 1106 1107 1108 1109 |
# File 'lib/carddb/collection.rb', line 1105 def records @records ||= (data['records'] || []).map do |rec| rec ? Record.new(rec, client: client) : nil end end |
#value ⇒ Object
Convenience: first value (for single-link fields)
1112 1113 1114 |
# File 'lib/carddb/collection.rb', line 1112 def value values.first end |
#values ⇒ Object
Returns all values (always an array)
1100 1101 1102 |
# File 'lib/carddb/collection.rb', line 1100 def values data['values'] || [] end |