Class: CodelessCode::Filters::Date::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/codeless_code/filters/date.rb

Overview

Wraps a Date and matches it against “date substrings”. ie: 2010-12 will matches any dates in December, 2010 and 2010 will match any dates in that year.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, match:) ⇒ Matcher


70
71
72
73
# File 'lib/codeless_code/filters/date.rb', line 70

def initialize(date, match:)
  @date = date
  @match = match
end

Class Method Details

.parse(str) ⇒ Object

param str [String] A date like 2010, 2010-12, or 2010-12-23


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/codeless_code/filters/date.rb', line 58

def self.parse(str)
  return nil unless str

  if str.size == 4
    new(::Date.parse("#{str}-01-01"), match: :year)
  elsif str.size == 7
    new(::Date.parse("#{str}-01"), match: :month)
  else
    new(::Date.parse(str), match: :day)
  end
end

Instance Method Details

#<=(other) ⇒ Object


83
84
85
# File 'lib/codeless_code/filters/date.rb', line 83

def <=(other)
  compare(@date, other, :<=, @match)
end

#==(other) ⇒ Object


75
76
77
# File 'lib/codeless_code/filters/date.rb', line 75

def ==(other)
  compare(@date, other, :==, @match)
end

#>=(other) ⇒ Object


79
80
81
# File 'lib/codeless_code/filters/date.rb', line 79

def >=(other)
  compare(@date, other, :>=, @match)
end