Sha256: 407ee06a04d6eab1aaf1f123aceb6788324b043196f601554a2c9fb46f958298

Contents?: true

Size: 635 Bytes

Versions: 1

Compression:

Stored size: 635 Bytes

Contents

module SQLTree::Node
  
  class Variable < Base

    attr_accessor :name

    def initialize(name)
      @name = name
    end
  
    def to_sql
      quote_var(@name)
    end
    
    def to_tree
      @name.to_sym
    end
    
    def ==(other)
      other.name == self.name
    end

    def self.parse(tokens)
      if SQLTree::Token::Variable === tokens.peek
        if tokens.peek(2) == SQLTree::Token::DOT
          SQLTree::Node::Field.parse(tokens)
        else
          self.new(tokens.next.literal)
        end
      else
        raise SQLTree::Parser::UnexpectedToken.new(tokens.peek, :variable)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sql_tree-0.0.1 lib/sql_tree/node/variable.rb