Class: Urbit::Graph
- Inherits:
-
Object
- Object
- Urbit::Graph
- Defined in:
- lib/urbit/graph.rb
Instance Attribute Summary collapse
-
#host_ship_name ⇒ Object
readonly
Returns the value of attribute host_ship_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ship ⇒ Object
readonly
Returns the value of attribute ship.
Instance Method Summary collapse
- #add_node(node:) ⇒ Object
- #creator ⇒ Object
- #description ⇒ Object
- #group ⇒ Object
- #group=(a_group) ⇒ Object
- #host_ship ⇒ Object
-
#initialize(ship:, graph_name:, host_ship_name:) ⇒ Graph
constructor
A new instance of Graph.
-
#newer_sibling_nodes(node:, count:) ⇒ Object
Answers the count newer sibling nodes relative to the passed #node.
- #newest_nodes(count: 10) ⇒ Object
-
#node(index:) ⇒ Object
Finds a single node in this graph by its index.
-
#nodes ⇒ Object
Answers an array with all of this Graph’s currently attached Nodes, recursively inluding all of the Node’s children.
-
#older_sibling_nodes(node:, count:) ⇒ Object
Answers the count older sibling nodes relative to the passed #node.
- #oldest_nodes(count: 10) ⇒ Object
- #resource ⇒ Object
- #title ⇒ Object
-
#to_s ⇒ Object
the canonical printed representation of a Graph.
- #type ⇒ Object
Constructor Details
#initialize(ship:, graph_name:, host_ship_name:) ⇒ Graph
Returns a new instance of Graph.
9 10 11 12 13 14 15 |
# File 'lib/urbit/graph.rb', line 9 def initialize(ship:, graph_name:, host_ship_name:) @ship = ship @group = nil @host_ship_name = host_ship_name @name = graph_name @nodes = SortedSet.new end |
Instance Attribute Details
#host_ship_name ⇒ Object (readonly)
Returns the value of attribute host_ship_name.
7 8 9 |
# File 'lib/urbit/graph.rb', line 7 def host_ship_name @host_ship_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/urbit/graph.rb', line 7 def name @name end |
#ship ⇒ Object (readonly)
Returns the value of attribute ship.
7 8 9 |
# File 'lib/urbit/graph.rb', line 7 def ship @ship end |
Instance Method Details
#add_node(node:) ⇒ Object
17 18 19 |
# File 'lib/urbit/graph.rb', line 17 def add_node(node:) @nodes << node unless node.deleted? end |
#creator ⇒ Object
21 22 23 24 |
# File 'lib/urbit/graph.rb', line 21 def creator self.fetch_link if @creator.nil? @creator end |
#description ⇒ Object
26 27 28 29 |
# File 'lib/urbit/graph.rb', line 26 def description self.fetch_link if @description.nil? @description end |
#group ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/urbit/graph.rb', line 31 def group if @group.nil? @link = self.fetch_link @group = @link.group unless @link.nil? end @group end |
#group=(a_group) ⇒ Object
39 40 41 |
# File 'lib/urbit/graph.rb', line 39 def group=(a_group) @group = a_group end |
#host_ship ⇒ Object
43 44 45 |
# File 'lib/urbit/graph.rb', line 43 def host_ship "~#{@host_ship_name}" end |
#newer_sibling_nodes(node:, count:) ⇒ Object
Answers the count newer sibling nodes relative to the passed #node.
99 100 101 |
# File 'lib/urbit/graph.rb', line 99 def newer_sibling_nodes(node:, count:) self.fetch_sibling_nodes(node, :newer, count)[0..(count - 1)] end |
#newest_nodes(count: 10) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/urbit/graph.rb', line 79 def newest_nodes(count: 10) count = 1 if count < 1 return self.fetch_newest_nodes(count) if @nodes.empty? || @nodes.count < count last_node = self.nodes.count - 1 self.nodes[(last_node - count)..last_node] end |
#node(index:) ⇒ Object
Finds a single node in this graph by its index. The index here should be the atom representation (as returned by Node#index).
59 60 61 |
# File 'lib/urbit/graph.rb', line 59 def node(index:) self.fetch_node(index).first end |
#nodes ⇒ Object
Answers an array with all of this Graph’s currently attached Nodes, recursively inluding all of the Node’s children.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/urbit/graph.rb', line 67 def nodes self.fetch_all_nodes if @nodes.empty? @all_n = [] @nodes.each do |n| @all_n << n n.children.each do |c| @all_n << c end end @all_n end |
#older_sibling_nodes(node:, count:) ⇒ Object
Answers the count older sibling nodes relative to the passed #node.
106 107 108 |
# File 'lib/urbit/graph.rb', line 106 def older_sibling_nodes(node:, count:) self.fetch_sibling_nodes(node, :older, count)[0..(count - 1)] end |
#oldest_nodes(count: 10) ⇒ Object
86 87 88 89 90 |
# File 'lib/urbit/graph.rb', line 86 def oldest_nodes(count: 10) count = 1 if count < 1 return self.fetch_oldest_nodes(count) if @nodes.empty? || @nodes.count < count self.nodes[0..(count - 1)] end |
#resource ⇒ Object
92 93 94 |
# File 'lib/urbit/graph.rb', line 92 def resource "#{self.host_ship}/#{self.name}" end |
#title ⇒ Object
110 111 112 113 |
# File 'lib/urbit/graph.rb', line 110 def title self.fetch_link if @title.nil? @title end |
#to_s ⇒ Object
the canonical printed representation of a Graph
122 123 124 |
# File 'lib/urbit/graph.rb', line 122 def to_s "a Graph(#{self.resource})" end |
#type ⇒ Object
115 116 117 118 |
# File 'lib/urbit/graph.rb', line 115 def type self.fetch_link if @type.nil? @type end |