Class: Lutaml::Rdf::Mapping

Inherits:
Model::Mapping show all
Defined in:
lib/lutaml/rdf/mapping.rb

Direct Known Subclasses

Turtle::Mapping

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model::Mapping

#add_listener, #all_listeners, #ensure_mappings_imported!, #inherit_from, #listeners_for, #omit_element, #omit_listener, #parent_mapping

Constructor Details

#initializeMapping

Returns a new instance of Mapping.



9
10
11
12
13
14
15
16
# File 'lib/lutaml/rdf/mapping.rb', line 9

def initialize
  super
  @namespace_set = Lutaml::Rdf::NamespaceSet.new
  @rdf_subject = nil
  @rdf_type = []
  @rdf_predicates = []
  @rdf_members = []
end

Instance Attribute Details

#namespace_setObject (readonly)

Returns the value of attribute namespace_set.



6
7
8
# File 'lib/lutaml/rdf/mapping.rb', line 6

def namespace_set
  @namespace_set
end

#rdf_membersObject (readonly)

Returns the value of attribute rdf_members.



6
7
8
# File 'lib/lutaml/rdf/mapping.rb', line 6

def rdf_members
  @rdf_members
end

#rdf_predicatesObject (readonly)

Returns the value of attribute rdf_predicates.



6
7
8
# File 'lib/lutaml/rdf/mapping.rb', line 6

def rdf_predicates
  @rdf_predicates
end

#rdf_subjectObject (readonly)

Returns the value of attribute rdf_subject.



6
7
8
# File 'lib/lutaml/rdf/mapping.rb', line 6

def rdf_subject
  @rdf_subject
end

#rdf_typeObject (readonly)

Returns the value of attribute rdf_type.



6
7
8
# File 'lib/lutaml/rdf/mapping.rb', line 6

def rdf_type
  @rdf_type
end

Instance Method Details

#deep_dupObject



65
66
67
# File 'lib/lutaml/rdf/mapping.rb', line 65

def deep_dup
  dup
end

#finalize(_mapper_class) ⇒ Object



53
# File 'lib/lutaml/rdf/mapping.rb', line 53

def finalize(_mapper_class); end

#finalized?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/lutaml/rdf/mapping.rb', line 55

def finalized?
  true
end

#initialize_copy(source) ⇒ Object



69
70
71
72
73
74
# File 'lib/lutaml/rdf/mapping.rb', line 69

def initialize_copy(source)
  super
  @rdf_type = source.rdf_type.dup
  @rdf_predicates = source.rdf_predicates.dup
  @rdf_members = source.rdf_members.dup
end

#map_element(name, to:) ⇒ Object



59
60
61
62
63
# File 'lib/lutaml/rdf/mapping.rb', line 59

def map_element(name, to:)
  raise Lutaml::Model::IncorrectMappingArgumentsError,
        "RDF mappings use `predicate` instead of `map_element`. " \
        "Use `predicate :#{name}, namespace: MyNs, to: :#{to}` inside `rdf do`."
end

#mappings(_register_id = nil) ⇒ Object



49
50
51
# File 'lib/lutaml/rdf/mapping.rb', line 49

def mappings(_register_id = nil)
  @rdf_predicates
end

#members(attr_name, predicate_name: nil, namespace: nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/lutaml/rdf/mapping.rb', line 41

def members(attr_name, predicate_name: nil, namespace: nil)
  @rdf_members << Lutaml::Rdf::MemberRule.new(
    attr_name,
    predicate_name: predicate_name,
    namespace: namespace,
  )
end

#namespace(*namespace_classes) ⇒ Object



18
19
20
# File 'lib/lutaml/rdf/mapping.rb', line 18

def namespace(*namespace_classes)
  @namespace_set = Lutaml::Rdf::NamespaceSet.new(*namespace_classes)
end

#predicate(name, namespace:, to:, lang_tagged: false, uri_reference: false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/lutaml/rdf/mapping.rb', line 30

def predicate(name, namespace:, to:, lang_tagged: false,
              uri_reference: false)
  @rdf_predicates << Lutaml::Rdf::MappingRule.new(
    name,
    namespace: namespace,
    to: to,
    lang_tagged: lang_tagged,
    uri_reference: uri_reference,
  )
end

#subjectObject



22
23
24
# File 'lib/lutaml/rdf/mapping.rb', line 22

def subject(&)
  @rdf_subject = Proc.new(&) if block_given?
end

#type(value) ⇒ Object



26
27
28
# File 'lib/lutaml/rdf/mapping.rb', line 26

def type(value)
  @rdf_type = Array(value)
end