Sha256: a30944194abd971f4a1709ce736709540af2a4bb18df76c8c6f0b294208a90e2

Contents?: true

Size: 797 Bytes

Versions: 4

Compression:

Stored size: 797 Bytes

Contents

require 'search_lingo/parsers/mdy'

module SearchLingo
  module Parsers
    class DateParser
      include MDY

      def initialize(table, column, operator = nil, **options)
        @table    = table
        @column   = column
        @prefix   = %r{#{operator}:\s*} if operator

        post_initialize **options
      end

      attr_reader :table, :column, :prefix

      def call(token)
        token.match /\A#{prefix}(?<date>#{US_DATE})\z/ do |m|
          date = parse m[:date]
          [:where, { table => { column => date } }] if date
        end
      end

      def post_initialize(**)
      end

      def inspect
        '#<%s:0x%x @table=%s @column=%s @prefix=%s>' %
          [self.class, object_id << 1, table.inspect, column.inspect, prefix.inspect]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
search_lingo-1.0.1 lib/search_lingo/parsers/date_parser.rb
search_lingo-1.0.0 lib/search_lingo/parsers/date_parser.rb
search_lingo-1.0.0.beta3 lib/search_lingo/parsers/date_parser.rb
search_lingo-1.0.0.beta2 lib/search_lingo/parsers/date_parser.rb