Sha256: 470df3bb422a0e849b5cd68d8bf494ec46ddd1395fe97e4c947f29fb59352753

Contents?: true

Size: 835 Bytes

Versions: 16

Compression:

Stored size: 835 Bytes

Contents

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
geoff-0.2.6 spec/support/geof_matchers.rb
geoff-0.2.5 spec/support/geof_matchers.rb
geoff-0.2.3 spec/support/geof_matchers.rb
geoff-0.2.2 spec/support/geof_matchers.rb
geoff-0.2.1 spec/support/geof_matchers.rb
geoff-0.2.0 spec/support/geof_matchers.rb
geoff-0.1.2 spec/support/geof_matchers.rb
geoff-0.1.1 spec/support/geof_matchers.rb
geoff-0.1.0 spec/support/geof_matchers.rb
geoff-0.0.8 spec/support/geof_matchers.rb
geoff-0.0.7 spec/support/geof_matchers.rb
geoff-0.0.6 spec/support/geof_matchers.rb
geoff-0.0.5 spec/support/geof_matchers.rb
geoff-0.0.4 spec/support/geof_matchers.rb
geoff-0.0.3.beta spec/support/geof_matchers.rb
geoff-0.0.2.beta spec/support/geof_matchers.rb