Class: Claus::AST::Hash

Inherits:
Node
  • Object
show all
Defined in:
lib/claus.rb

Overview

TODO: refactor case statements

Instance Attribute Summary

Attributes inherited from Node

#ast

Instance Method Summary collapse

Methods inherited from Node

#initialize

Constructor Details

This class inherits a constructor from Claus::AST::Node

Instance Method Details

#compile(expression) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/claus.rb', line 56

def compile expression
  expression.each_with_object({}) do |(k, v), h|
    case v
      when ::Hash   then h[k] = Hash.new(v)
      when ::Array  then h[k] = List.new(v)
      when ::Range  then h[k] = List.new(v)
      when Claus    then h[k] = v.ast
      else               h[k] = v.kind_of?(Node) ? v : Node.new(v)
    end
  end
end

#match?(value) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/claus.rb', line 68

def match? value
  return false unless ::Hash === value
  ast.each do |k, node|
    return false unless value.key?(k) && node.match?(value[k])
  end
  true
end