Class: Lutaml::Rdf::MemberRule

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/rdf/member_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_name, predicate_name: nil, namespace: nil, link: nil) ⇒ MemberRule

Returns a new instance of MemberRule.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lutaml/rdf/member_rule.rb', line 8

def initialize(attr_name, predicate_name: nil, namespace: nil, link: nil)
  if predicate_name && !namespace
    raise ArgumentError,
          "namespace is required when predicate_name is provided"
  end

  if predicate_name && link
    raise ArgumentError,
          "predicate_name and link are mutually exclusive"
  end

  @attr_name = attr_name.to_sym
  @predicate_name = predicate_name
  @namespace = namespace
  @link = link
end

Instance Attribute Details

#attr_nameObject (readonly)

Returns the value of attribute attr_name.



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

def attr_name
  @attr_name
end

Returns the value of attribute link.



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

def link
  @link
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#predicate_nameObject (readonly)

Returns the value of attribute predicate_name.



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

def predicate_name
  @predicate_name
end

Instance Method Details



35
36
37
38
39
40
41
42
43
44
# File 'lib/lutaml/rdf/member_rule.rb', line 35

def link_predicate_for(member, resolver)
  return nil unless @link

  case @link
  when String
    resolver.call(@link)
  when Proc
    resolver.call(@link.call(member))
  end
end

#linked?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/lutaml/rdf/member_rule.rb', line 25

def linked?
  !!(@predicate_name || @link)
end

#linked_predicate_uriObject



29
30
31
32
33
# File 'lib/lutaml/rdf/member_rule.rb', line 29

def linked_predicate_uri
  return nil unless @predicate_name

  @namespace[@predicate_name]
end


46
47
48
49
50
51
52
# File 'lib/lutaml/rdf/member_rule.rb', line 46

def resolve_link_uri(member, resolver)
  if @predicate_name
    linked_predicate_uri
  elsif @link
    link_predicate_for(member, resolver)
  end
end