Class: IqRdf::Predicate

Inherits:
Uri show all
Defined in:
lib/iq_rdf/predicate.rb

Instance Attribute Summary collapse

Attributes inherited from Uri

#namespace, #rdf_type, #uri_postfix

Attributes inherited from Node

#lang, #nodes

Instance Method Summary collapse

Methods inherited from Uri

#add_blank_node, #full_uri, #is_subject?, #to_s

Methods inherited from Node

#<<, #build_full_uri_predicate, #is_subject?, #method_missing, #xml_lang

Constructor Details

#initialize(namespace, uri_postfix, subject, lang = nil) ⇒ Predicate

Returns a new instance of Predicate.



20
21
22
23
# File 'lib/iq_rdf/predicate.rb', line 20

def initialize(namespace, uri_postfix, subject, lang = nil)
  super(namespace, uri_postfix, nil, lang)
  @subject = subject
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class IqRdf::Node

Instance Attribute Details

#subjectObject (readonly)

Returns the value of attribute subject.



18
19
20
# File 'lib/iq_rdf/predicate.rb', line 18

def subject
  @subject
end

Instance Method Details

#build_xml(xml) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/iq_rdf/predicate.rb', line 25

def build_xml(xml)
  nodes.each do |node|
    node.build_xml(xml) do |*args|
      block = args.pop if args.last.is_a?(Proc)
      params = if namespace.token.nil? # Full uri
        nameStartChar = "[A-Z]|_|[a-z]|[\u{00C0}-\u{00D6}]|[\u{00D8}-\u{00F6}]|[\u{00F8}-\u{02FF}]|[\u{0370}-\u{037D}]|[\u{037F}-\u{1FFF}]|[\u{200C}-\u{200D}]|[\u{2070}-\u{218F}]|[\u{2C00}-\u{2FEF}]|[\u{3001}-\u{D7FF}]|[\u{F900}-\u{FDCF}]|[\u{FDF0}-\u{FFFD}]|[\u{10000}-\u{EFFFF}]"
        name = Regexp.new("^(.*?)((#{nameStartChar})(#{nameStartChar}|-|[0-9]|\u{00B7}|[\u{0300}-\u{036F}]|[\u{203F}-\u{2040}])*)$")
        unless matches = name.match(self.uri_postfix.to_s)
          raise "Coudln't extract namespace and postfix from URI '#{self.uri_postfix}'"
        end
        ["ns0", matches[2].to_sym, {"xmlns:ns0" => matches[1]}]
      else
        namespace.token == :default ? [self.uri_postfix.to_s] : [namespace.token.to_s, self.uri_postfix.to_sym]
      end
      params += args
      params << {"xml:lang" => xml_lang} if xml_lang
      if block
        xml.tag!(*params) do
          block.call
        end
      else
        xml.tag!(*params)
      end
    end
  end
end