Class: Unit::Types::RelationshipArray
- Inherits:
-
Object
- Object
- Unit::Types::RelationshipArray
- Defined in:
- lib/unit/types/relationship_array.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(array) ⇒ RelationshipArray
constructor
A new instance of RelationshipArray.
- #to_hash ⇒ Object
Constructor Details
#initialize(array) ⇒ RelationshipArray
Returns a new instance of RelationshipArray.
10 11 12 |
# File 'lib/unit/types/relationship_array.rb', line 10 def initialize(array) @data = array end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/unit/types/relationship_array.rb', line 7 def data @data end |
Class Method Details
.from_params_array(array) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/unit/types/relationship_array.rb', line 18 def self.from_params_array(array) @relationships = [] array.map do |item| @relationships << if item.is_a?(Relationship) item.to_hash[:data] else Relationship.new(item[:type], item[:id]).to_hash[:data] end end RelationshipArray.new(@relationships).to_hash end |
Instance Method Details
#to_hash ⇒ Object
14 15 16 |
# File 'lib/unit/types/relationship_array.rb', line 14 def to_hash { "data": data } end |