Class: SearchLingo::Parsers::DateParser
- Inherits:
-
Object
- Object
- SearchLingo::Parsers::DateParser
- Includes:
- MDY
- Defined in:
- lib/search_lingo/parsers/date_parser.rb
Constant Summary
Constants included from MDY
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#call(token) ⇒ Object
Attempts to parse the token as a date, closed date range, or open date range.
-
#initialize(column, modifier: nil) ⇒ DateParser
constructor
Instantiates a new DateParser object.
-
#inspect ⇒ Object
:nodoc:.
Methods included from MDY
Constructor Details
permalink #initialize(column, modifier: nil) ⇒ DateParser
Instantiates a new DateParser object.
The required argument column
should be an Arel attribute.
If present, the optional argument modifier
will be used as the operator which precedes the date term.
DateParser.new Booking.arel_table DateParser.new Contract.arel_table, modifier: ‘contract’
18 19 20 21 |
# File 'lib/search_lingo/parsers/date_parser.rb', line 18 def initialize(column, modifier: nil) @column = column @prefix = %r{#{modifier}:[[:space:]]*} if modifier end |
Instance Attribute Details
permalink #column ⇒ Object (readonly)
Returns the value of attribute column.
23 24 25 |
# File 'lib/search_lingo/parsers/date_parser.rb', line 23 def column @column end |
permalink #prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
23 24 25 |
# File 'lib/search_lingo/parsers/date_parser.rb', line 23 def prefix @prefix end |
Instance Method Details
permalink #call(token) ⇒ Object
Attempts to parse the token as a date, closed date range, or open date range.
Examples of single dates are 7/14, 7/14/17, and 7/14/2017. Examples of closed date ranges are 1/1-6/30 and 7/1/16-6/30/18. Examples of open date ranges are -6/30 and 7/1/17-.
32 33 34 35 36 37 |
# File 'lib/search_lingo/parsers/date_parser.rb', line 32 def call(token) parse_single_date(token) || parse_date_range(token) || parse_lte_date(token) || parse_gte_date(token) end |
permalink #inspect ⇒ Object
:nodoc:
39 40 41 42 |
# File 'lib/search_lingo/parsers/date_parser.rb', line 39 def inspect # :nodoc: '#<%s:0x%x @prefix=%s @column=%s>' % [self.class, object_id << 1, prefix.inspect, column.inspect] end |