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.
2140 2141 2142 2143 |
# File 'lib/carddb/collection.rb', line 2140 def initialize(data, client: nil) @data = data || {} @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
2138 2139 2140 |
# File 'lib/carddb/collection.rb', line 2138 def client @client end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
2138 2139 2140 |
# File 'lib/carddb/collection.rb', line 2138 def data @data end |
Instance Method Details
#field ⇒ Object
2145 2146 2147 |
# File 'lib/carddb/collection.rb', line 2145 def field data['field'] end |
#link_field_key ⇒ Object
2149 2150 2151 |
# File 'lib/carddb/collection.rb', line 2149 def link_field_key data['linkFieldKey'] end |
#record ⇒ Object
Convenience: first record (for single-link fields)
2171 2172 2173 |
# File 'lib/carddb/collection.rb', line 2171 def record records.first end |
#records ⇒ Object
Returns all resolved records (parallel array to values, nil for unresolved)
2159 2160 2161 2162 2163 |
# File 'lib/carddb/collection.rb', line 2159 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)
2166 2167 2168 |
# File 'lib/carddb/collection.rb', line 2166 def value values.first end |
#values ⇒ Object
Returns all values (always an array)
2154 2155 2156 |
# File 'lib/carddb/collection.rb', line 2154 def values data['values'] || [] end |