require 'json' def parse_geoff_node(expr) GeoffNodeMatcher.new(expr) end def parse_geoff_relation(expr) GeoffRelationshipMatcher.new(expr) end def strip_whitespace s s.gsub(/^\s*/, '').chomp end class GeoffNodeMatcher @@regex = /\((\w+)\) (.*)/ def initialize(expression) @@regex.match expression @node_name = $1 @attributes = JSON.parse($2, symbolize_names: true) rescue @attributes = {} end def named?(name) @node_name == name end def has_attribute?(name, value) @attributes[name.to_sym] == value end end class GeoffRelationshipMatcher @@regex = /\((.*)\)-\[\:(.*)\]->\((.*)\)/ def initialize(expression) @@regex.match expression @source_name = $1 @relationship_name = $2 @dest_name = $3 end def named?(name) @relationship_name == name end end