Module: RDF::NodeProxy
- Defined in:
- lib/lightrdf/node_proxy.rb
Overview
This class allows instantiating RDF resources as Ruby objects
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other_node) ⇒ Object
Equality method delegated to node.
-
#clone ⇒ Object
clone method delegated to node.
-
#eql?(other_node) ⇒ Boolean
Equality method delegated to node.
-
#hash ⇒ Object
Hash method delegated to node.
-
#id ⇒ Object
id method delegated to node.
-
#initialize(arg = nil) ⇒ Object
Constructor that allows.
-
#method_missing(method, *args) ⇒ Object
Any other method (including any predicate) delegated to node.
- #rdf_type ⇒ Object
-
#to_s ⇒ Object
to_s method delegated to node.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Any other method (including any predicate) delegated to node
71 72 73 |
# File 'lib/lightrdf/node_proxy.rb', line 71 def method_missing method, *args @node.send method, *args end |
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 |
# File 'lib/lightrdf/node_proxy.rb', line 4 def self.included base base.extend ClassMethods base.send :attr_reader, :node base.maps(base.to_s.gsub("::",":").gsub(/\A.*:/) { |a| a.downcase }) end |
Instance Method Details
#==(other_node) ⇒ Object
Equality method delegated to node
39 40 41 |
# File 'lib/lightrdf/node_proxy.rb', line 39 def == other_node eql? other_node end |
#clone ⇒ Object
clone method delegated to node
62 63 64 |
# File 'lib/lightrdf/node_proxy.rb', line 62 def clone node.clone.proxy(rdf_type) end |
#eql?(other_node) ⇒ Boolean
Equality method delegated to node
43 44 45 |
# File 'lib/lightrdf/node_proxy.rb', line 43 def eql? other_node self.class == other_node.class and @node.id == other_node.node.id end |
#hash ⇒ Object
Hash method delegated to node
47 48 49 |
# File 'lib/lightrdf/node_proxy.rb', line 47 def hash # Hack for Ruby 1.8.6 @node.id.hash ^ self.class.hash end |
#id ⇒ Object
id method delegated to node
57 58 59 |
# File 'lib/lightrdf/node_proxy.rb', line 57 def id @node.id end |
#initialize(arg = nil) ⇒ Object
Constructor that allows
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lightrdf/node_proxy.rb', line 23 def initialize arg=nil @node = if arg.is_a?(RDF::Node) arg elsif arg.is_a?(Hash) new_node = Node('*') new_node.rdf::type = rdf_type arg.each { |k,v| new_node[k] = (new_node[k] + [v].flatten).uniq } new_node else new_node = Node('*') new_node.rdf::type = rdf_type new_node end end |
#rdf_type ⇒ Object
66 67 68 |
# File 'lib/lightrdf/node_proxy.rb', line 66 def rdf_type self.class.instance_variable_get("@rdf_type") end |
#to_s ⇒ Object
to_s method delegated to node
52 53 54 |
# File 'lib/lightrdf/node_proxy.rb', line 52 def to_s @node.to_s end |