Class: RoadForest::Graph::FocusList
- Inherits:
-
RDF::List
- Object
- RDF::List
- RoadForest::Graph::FocusList
- Defined in:
- lib/roadforest/graph/focus-list.rb
Instance Attribute Summary collapse
-
#base_node ⇒ Object
Returns the value of attribute base_node.
-
#root_url ⇒ Object
Returns the value of attribute root_url.
Instance Method Summary collapse
- #append(value) ⇒ Object (also: #<<)
- #append_node(subject = nil) ⇒ Object
- #car ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
Instance Attribute Details
#base_node ⇒ Object
Returns the value of attribute base_node.
6 7 8 |
# File 'lib/roadforest/graph/focus-list.rb', line 6 def base_node @base_node end |
#root_url ⇒ Object
Returns the value of attribute root_url.
6 7 8 |
# File 'lib/roadforest/graph/focus-list.rb', line 6 def root_url @root_url end |
Instance Method Details
#append(value) ⇒ Object Also known as: <<
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/roadforest/graph/focus-list.rb', line 22 def append(value) value = case value when nil then RDF.nil when RDF::Value then value when Array then RDF::List.new(nil, graph, value) else value end if empty? new_subject = subject #graph.insert([new_subject, RDF.type, RDF.List]) else old_subject, new_subject = last_subject, RDF::Node.new graph.delete([old_subject, RDF.rest, RDF.nil]) graph.insert([old_subject, RDF.rest, new_subject]) end graph.insert([new_subject, RDF.first, value.is_a?(RDF::List) ? value.subject : value]) graph.insert([new_subject, RDF.rest, RDF.nil]) self end |
#append_node(subject = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/roadforest/graph/focus-list.rb', line 46 def append_node(subject=nil) if empty? and self.subject == RDF.nil raise "Attempted to append #{subject} to an empty list (remove the list and replace it)" end base_node.create_node(subject) do |node| append(node.subject) yield node if block_given? end end |
#car ⇒ Object
8 |
# File 'lib/roadforest/graph/focus-list.rb', line 8 alias car first |
#each ⇒ Object
15 16 17 18 19 20 |
# File 'lib/roadforest/graph/focus-list.rb', line 15 def each return to_enum unless block_given? super do |value| yield base_node.unwrap_value(value) end end |
#first ⇒ Object
11 12 13 |
# File 'lib/roadforest/graph/focus-list.rb', line 11 def first at(0) end |