Module: Agama::Keyify
- Defined in:
- lib/agama/keyify.rb
Class Method Summary collapse
- .edge(edge) ⇒ Object
- .node(node) ⇒ Object
- .parse(key) ⇒ Object
- .range(params) ⇒ Object
- .subkey?(subkey, key) ⇒ Boolean
Class Method Details
.edge(edge) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/agama/keyify.rb', line 10 def self.edge(edge) from = self.node(edge[:from]) type = edge[:type] || Config::DEFAULT_TYPE outgoing, incoming = if edge[:directed] then ["O", "I"] else ["N", "N"] end to = self.node(edge[:to]) key = [from, type, outgoing, to].join(Config::EDGE_DELIMITOR) reverse_key = [to, type, incoming, from].join(Config::EDGE_DELIMITOR) [key, reverse_key] end |
.node(node) ⇒ Object
5 6 7 8 |
# File 'lib/agama/keyify.rb', line 5 def self.node(node) type = node[:type] || Config::DEFAULT_TYPE [type, node[:name]].join(Config::NODE_DELIMITOR) end |
.parse(key) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/agama/keyify.rb', line 49 def self.parse(key) from_key, edge_type, direction, to_key = key.split(Config::EDGE_DELIMITOR) type, name = to_key.split(Config::NODE_DELIMITOR) directed = true directed = false if (direction == "N") [{:type => type, :name => name}, edge_type, direction, directed] end |
.range(params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/agama/keyify.rb', line 27 def self.range(params) from = self.node(params[:from]) if params[:from] type = params[:edge_type] if type dir = params[:direction] if dir to_type = params[:to_type] if to_type [from, type, dir, to_type].join(Config::EDGE_DELIMITOR) else [from, type, dir, nil].join(Config::EDGE_DELIMITOR) end else [from, type, nil].join(Config::EDGE_DELIMITOR) end else [from, nil].join(Config::EDGE_DELIMITOR) end end |
.subkey?(subkey, key) ⇒ Boolean
57 58 59 |
# File 'lib/agama/keyify.rb', line 57 def self.subkey?(subkey, key) key [0, subkey.length] == subkey end |