Class: Aspen::Node
- Inherits:
-
Object
- Object
- Aspen::Node
- Defined in:
- lib/aspen/node.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#nickname ⇒ Object
Returns the value of attribute nickname.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attribute_string ⇒ Object
-
#initialize(label:, attributes: {}) ⇒ Node
constructor
A new instance of Node.
- #nickname_from_first_attr_value ⇒ Object
- #nickname_node ⇒ Object
- #signature ⇒ Object
- #to_cypher ⇒ Object
Constructor Details
#initialize(label:, attributes: {}) ⇒ Node
Returns a new instance of Node.
12 13 14 15 16 |
# File 'lib/aspen/node.rb', line 12 def initialize(label: , attributes: {}) @label = label @attributes = attributes @nickname = nickname_from_first_attr_value end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/aspen/node.rb', line 9 def attributes @attributes end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
9 10 11 |
# File 'lib/aspen/node.rb', line 9 def label @label end |
#nickname ⇒ Object
Returns the value of attribute nickname.
9 10 11 |
# File 'lib/aspen/node.rb', line 9 def nickname @nickname end |
Instance Method Details
#==(other) ⇒ Object
46 47 48 49 50 |
# File 'lib/aspen/node.rb', line 46 def ==(other) label == other.label && attributes == other.attributes && nickname == other.nickname end |
#attribute_string ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/aspen/node.rb', line 38 def attribute_string attributes.to_s. gsub(/"(?<token>[[:alpha:]_]+)"=>/, '\k<token>: '). # This puts a single space inside curly braces. gsub(/\{(\s*)/, "{ "). gsub(/(\s*)\}/, " }") end |
#nickname_from_first_attr_value ⇒ Object
18 19 20 |
# File 'lib/aspen/node.rb', line 18 def nickname_from_first_attr_value "#{@label}-#{@attributes.values.first}".parameterize.underscore end |
#nickname_node ⇒ Object
30 31 32 |
# File 'lib/aspen/node.rb', line 30 def nickname_node "(#{nickname})" end |
#signature ⇒ Object
34 35 36 |
# File 'lib/aspen/node.rb', line 34 def signature "(#{label})" end |
#to_cypher ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/aspen/node.rb', line 22 def to_cypher if nickname "(#{nickname}:#{label} #{ attribute_string })" else "(#{label} #{ attribute_string })" end end |