Class: RDFObject::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf_objects/pho/rdf_resource.rb

Instance Method Summary collapse

Instance Method Details

#empty_graph?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rdf_objects/pho/rdf_resource.rb', line 53

def empty_graph?
  Curie.get_mappings.each do | prefix, uri |
    if self.respond_to?(prefix.to_sym)
      if uri == "http://schemas.talis.com/2005/dir/schema#"
        self["http://schemas.talis.com/2005/dir/schema#"].each_pair do |property, value|
          next if property == 'etag'
          return false
        end
      else
        return false
      end
    end
  end
  return true    
end

#rss_item_blockObject



23
24
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
51
# File 'lib/rdf_objects/pho/rdf_resource.rb', line 23

def rss_item_block
  rdf = "<item #{xml_subject_attribute}>"
  rdf << "<title>Item</title>"
  rdf << "<link>#{self.uri}</link>"
  namespaces = {}
  Curie.get_mappings.each_pair do |key, value|
    if self.respond_to?(key.to_sym)
      self.send(key.to_sym).each_pair do | predicate, objects |
        [*objects].each do | object |
          rdf << "<#{key}:#{predicate}"
          namespaces["xmlns:#{key}"] = "#{Curie.parse("[#{key}:]")}"
          if object.is_a?(RDFObject::ResourceReference) || object.is_a?(RDFObject::BlankNode)
            rdf << " #{object.xml_object_attribute} />"              
          else
            if object.language
              rdf << " xml:lang=\"#{object.language}\""
            end
            if object.datatype
              rdf << " rdf:datatype=\"#{object.datatype}\""
            end
            rdf << ">#{CGI.escapeHTML(object.to_s)}</#{key}:#{predicate}>"
          end
        end
      end
    end
  end
  rdf << "</item>"
  [namespaces, rdf]
end

#to_rssObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rdf_objects/pho/rdf_resource.rb', line 2

def to_rss
  namespaces, rdf_data = self.rss_item_block
  unless namespaces["xmlns:rdf"]
    if  x = namespaces.index("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
      namespaces.delete(x)
    end
    namespaces["xmlns:rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  end
  namespaces["xmlns"] = "http://purl.org/rss/1.0/"
  uri = self.uri.sub(/#.*$/,".rss")
  rdf = "<rdf:RDF"
  namespaces.each_pair {|key, value| rdf << " #{key}=\"#{value}\""}
  rdf <<">"
  rdf << "<channel rdf:about=\"#{uri}\"><title>#{self.uri}</title><link>#{self.uri}</link>"
  rdf << "<description>#{self.uri}</description><items><rdf:Seq><rdf:li resource=\"#{self.uri}\" /></rdf:Seq></items>"
  rdf << "</channel>"
  rdf << rdf_data
  rdf << "</rdf:RDF>"
  rdf      
end