Class: Grom::Node
- Inherits:
-
Object
- Object
- Grom::Node
- Defined in:
- lib/grom/node.rb
Overview
A Ruby object populated with n-triple data.
Constant Summary collapse
- BLANK =
'blank_node'.freeze
Instance Attribute Summary collapse
-
#statements ⇒ Array
readonly
an array of n-triple statements.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Checks if Grom::Node is a blank node.
-
#initialize(statements, decorators = nil) ⇒ Node
constructor
A new instance of Node.
-
#method_missing(method, *params, &block) ⇒ Object
Allows the user to access instance variables as methods or raise an error if the variable is not defined.
-
#respond_to_missing?(method, include_all = false) ⇒ Boolean
node = Grom::Node.new(statements).
Constructor Details
#initialize(statements, decorators = nil) ⇒ Node
Returns a new instance of Node.
12 13 14 15 16 |
# File 'lib/grom/node.rb', line 12 def initialize(statements, decorators = nil) @statements = statements populate(decorators) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params, &block) ⇒ Object
Allows the user to access instance variables as methods or raise an error if the variable is not defined.
43 44 45 |
# File 'lib/grom/node.rb', line 43 def method_missing(method, *params, &block) instance_variable_get("@#{method}".to_sym) || super end |
Instance Attribute Details
#statements ⇒ Array (readonly)
an array of n-triple statements.
6 7 8 |
# File 'lib/grom/node.rb', line 6 def statements @statements end |
Instance Method Details
#blank? ⇒ Boolean
Checks if Grom::Node is a blank node
70 71 72 |
# File 'lib/grom/node.rb', line 70 def blank? @statements.first.subject.anonymous? end |
#respond_to_missing?(method, include_all = false) ⇒ Boolean
node = Grom::Node.new(statements)
node.respond_to?(:forename) #=> 'Jane'
node.respond_to?(:foo) #=> false
63 64 65 |
# File 'lib/grom/node.rb', line 63 def respond_to_missing?(method, include_all = false) instance_variable_get("@#{method}".to_sym) || super end |