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.
2587 2588 2589 2590 |
# File 'lib/carddb/collection.rb', line 2587 def initialize(data, client: nil) @data = data || {} @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
2585 2586 2587 |
# File 'lib/carddb/collection.rb', line 2585 def client @client end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
2585 2586 2587 |
# File 'lib/carddb/collection.rb', line 2585 def data @data end |
Instance Method Details
#field ⇒ Object
2592 2593 2594 |
# File 'lib/carddb/collection.rb', line 2592 def field data['field'] end |
#link_field_key ⇒ Object
2596 2597 2598 |
# File 'lib/carddb/collection.rb', line 2596 def link_field_key data['linkFieldKey'] end |
#record ⇒ Object
Convenience: first record (for single-link fields)
2618 2619 2620 |
# File 'lib/carddb/collection.rb', line 2618 def record records.first end |
#records ⇒ Object
Returns all resolved records (parallel array to values, nil for unresolved)
2606 2607 2608 2609 2610 |
# File 'lib/carddb/collection.rb', line 2606 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)
2613 2614 2615 |
# File 'lib/carddb/collection.rb', line 2613 def value values.first end |
#values ⇒ Object
Returns all values (always an array)
2601 2602 2603 |
# File 'lib/carddb/collection.rb', line 2601 def values data['values'] || [] end |