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

Returns a new instance of Matcher.



58
59
60
61
# File 'lib/codeless_code/filters/date.rb', line 58

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/codeless_code/filters/date.rb', line 46

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



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

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

#==(other) ⇒ Object



63
64
65
# File 'lib/codeless_code/filters/date.rb', line 63

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

#>=(other) ⇒ Object



67
68
69
# File 'lib/codeless_code/filters/date.rb', line 67

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