Module: RDF::Serializers::Relationship
- Includes:
- HextupleSerializer
- Defined in:
- lib/rdf/serializers/relationship.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
-
#image ⇒ Object
Returns the value of attribute image.
-
#predicate ⇒ Object
Returns the value of attribute predicate.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
Instance Method Summary collapse
- #include_relationship?(record, serialization_params, included = false) ⇒ Boolean
- #iris_from_record_and_relationship(record, params = {}) ⇒ Object
- #relationship_sequence(record, iris, serialization_params) ⇒ Object
- #relationship_statements(record, iris, serialization_params) ⇒ Object
- #serialize_hex(record, included, serialization_params) ⇒ Object
Methods included from HextupleSerializer
#iri_from_record, #normalized_object, #object_datatype, #object_value, #operation, #value_to_hex
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
8 9 10 |
# File 'lib/rdf/serializers/relationship.rb', line 8 def association @association end |
#image ⇒ Object
Returns the value of attribute image.
8 9 10 |
# File 'lib/rdf/serializers/relationship.rb', line 8 def image @image end |
#predicate ⇒ Object
Returns the value of attribute predicate.
8 9 10 |
# File 'lib/rdf/serializers/relationship.rb', line 8 def predicate @predicate end |
#sequence ⇒ Object
Returns the value of attribute sequence.
8 9 10 |
# File 'lib/rdf/serializers/relationship.rb', line 8 def sequence @sequence end |
Instance Method Details
#include_relationship?(record, serialization_params, included = false) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/rdf/serializers/relationship.rb', line 43 def include_relationship?(record, serialization_params, included = false) return false if lazy_load_data && !included super(record, serialization_params) end |
#iris_from_record_and_relationship(record, params = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rdf/serializers/relationship.rb', line 49 def iris_from_record_and_relationship(record, params = {}) initialize_static_serializer unless @initialized_static_serializer associated_object = fetch_associated_object(record, params) return [] unless associated_object if associated_object.respond_to? :map return associated_object.compact.map do |object| iri_from_record(object) end end [iri_from_record(associated_object)] end |
#relationship_sequence(record, iris, serialization_params) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rdf/serializers/relationship.rb', line 18 def relationship_sequence(record, iris, serialization_params) return [] if iris.blank? sequence = RDF::Node.new [ value_to_hex(iri_from_record(record).to_s, predicate, sequence, nil, serialization_params), value_to_hex(sequence, RDF.type, RDF.Seq, nil, serialization_params) ] + iris.map.with_index do |iri, index| value_to_hex(sequence, RDF["_#{index}"], iri, nil, serialization_params) end end |
#relationship_statements(record, iris, serialization_params) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rdf/serializers/relationship.rb', line 31 def relationship_statements(record, iris, serialization_params) iris.map do || value_to_hex( iri_from_record(record).to_s, predicate, , nil, serialization_params ) end end |
#serialize_hex(record, included, serialization_params) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/rdf/serializers/relationship.rb', line 10 def serialize_hex(record, included, serialization_params) return [] unless include_relationship?(record, serialization_params, included) && predicate.present? iris = iris_from_record_and_relationship(record, serialization_params) sequence ? relationship_sequence(record, iris, serialization_params) : relationship_statements(record, iris, serialization_params) end |