Sha256: 3cad80d913fcbf4a24a28802e202543913533ce7dc78189f5e5f6dbdfaf149b9

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

module Rdbc
  module Translating
    def method_pre(method)
       method_with_prefix(method, :pre)
    end

    def method_post(method)
      method_with_prefix(method, :post)
    end

    def method_with_prefix(method, type)
      operator = operator(method)
      ( type.to_s + '_' +
        if operator.nil?
          method.to_s
        else
          'op_' + operator.to_s
        end
      ).to_sym
    end

    def operator(method)
      {
        :[]  => :element_read,
        :[]= => :element_write,
        :**  => :power,
        :~   => :not,
        :+@  => :unary_plus,
        :-@  => :unary_minus,
        :*   => :product,
        :/   => :quotient,
        :%   => :modulo,
        :+   => :plus,
        :-   => :minus,
        :>>  => :right_shift,
        :<<  => :left_shift,
        :&   => :and,
        :^   => :xor,
        :|   => :or,
        :<=  => :less_or_equal,
        :<   => :less,
        :>   => :greater,
        :>=  => :greater_or_equal,
        :<=> => :comparison,
        :==  => :eql,
        :=== => :case_comparison,
        :=~  => :match
      }[method]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
armin-joellenbeck-rdbc-0.2.3 lib/rdbc/translating.rb
armin-joellenbeck-rdbc-0.2.4 lib/rdbc/translating.rb
armin-joellenbeck-rdbc-0.2.5 lib/rdbc/translating.rb