Sha256: e167b590ea02693cb3a1be4112ee38a3bc77c5cb58b679a845ee799e41311bc8

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'search_lingo/parsers/date_parser'
require 'forwardable'

module SearchLingo
  module Parsers # :nodoc:
    class OpenDateRangeParser < DateParser
      extend Forwardable

      def call(token)
        parse_lte(token) || parse_gte(token)
      end

      def post_initialize(connection:, **)
        @connection = connection
      end

      def_delegators :@connection, :quote_column_name, :quote_table_name

      private

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
search_lingo-1.0.2 lib/search_lingo/parsers/open_date_range_parser.rb