Module: Gyunyu::Command::Export::CustomFilter

Defined in:
lib/gyunyu/command/export/custom_filter.rb

Constant Summary collapse

START_SECOND =
'T23:59:59Z'
LAST_SECOND =
'T24:00:00Z'

Class Method Summary collapse

Class Method Details

.filterObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gyunyu/command/export/custom_filter.rb', line 13

def filter
  filter = {}

  %w( yesterday today tomorrow last_week this_week next_week
      last_month this_month next_month ).each { |term|
    due = [
      "dueAfter:" + send("from_#{term}"),
      "dueBefore:" + send("until_#{term}")
    ].join( ' and ' )
    filter[term] = due
    filter["#{term}_yet"] = due + incomplete
  }

  filter
end

.from_last_monthObject



115
116
117
118
# File 'lib/gyunyu/command/export/custom_filter.rb', line 115

def from_last_month
  d = today << 2
  Date.new( d.year, d.mon, -1 ).to_s + START_SECOND
end

.from_last_weekObject



79
80
81
82
83
84
85
# File 'lib/gyunyu/command/export/custom_filter.rb', line 79

def from_last_week
  if today.sunday?
    (last_sunday - 1).to_s + START_SECOND
  else
    (last_sunday - 8).to_s + START_SECOND
  end
end

.from_next_monthObject



135
136
137
138
# File 'lib/gyunyu/command/export/custom_filter.rb', line 135

def from_next_month
  d = today
  Date.new( d.year, d.mon, -1 ).to_s + START_SECOND
end

.from_next_weekObject



107
108
109
# File 'lib/gyunyu/command/export/custom_filter.rb', line 107

def from_next_week
  (next_sunday - 1).to_s + START_SECOND
end

.from_this_monthObject



125
126
127
128
# File 'lib/gyunyu/command/export/custom_filter.rb', line 125

def from_this_month
  d = today << 1
  Date.new( d.year, d.mon, -1 ).to_s + START_SECOND
end

.from_this_weekObject



95
96
97
98
99
100
101
# File 'lib/gyunyu/command/export/custom_filter.rb', line 95

def from_this_week
  if today.sunday?
    (today - 1).to_s + START_SECOND
  else
    (last_sunday - 1).to_s + START_SECOND
  end
end

.from_todayObject



63
64
65
# File 'lib/gyunyu/command/export/custom_filter.rb', line 63

def from_today
  (today - 1).to_s + START_SECOND
end

.from_tomorrowObject



71
72
73
# File 'lib/gyunyu/command/export/custom_filter.rb', line 71

def from_tomorrow
  today.to_s + START_SECOND
end

.from_yesterdayObject



55
56
57
# File 'lib/gyunyu/command/export/custom_filter.rb', line 55

def from_yesterday
  (today - 2).to_s + START_SECOND
end

.incompleteObject



145
146
147
# File 'lib/gyunyu/command/export/custom_filter.rb', line 145

def incomplete
  ' and status:incomplete'
end

.last_sundayObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gyunyu/command/export/custom_filter.rb', line 29

def last_sunday
  if today.sunday?
    today - 7
  else
    proc { |d|
      until d.sunday?
        d -= 1
      end
      d
    }.call(today)
  end
end

.next_sundayObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gyunyu/command/export/custom_filter.rb', line 42

def next_sunday
  if today.sunday?
    today + 7
  else
    proc { |d|
      until d.sunday?
        d += 1
      end
      d
    }.call(today)
  end
end

.todayObject



9
10
11
# File 'lib/gyunyu/command/export/custom_filter.rb', line 9

def today
  Date.today
end

.until_last_monthObject



120
121
122
123
# File 'lib/gyunyu/command/export/custom_filter.rb', line 120

def until_last_month
  d = today << 1
  Date.new( d.year, d.mon, -1 ).to_s + LAST_SECOND
end

.until_last_weekObject



87
88
89
90
91
92
93
# File 'lib/gyunyu/command/export/custom_filter.rb', line 87

def until_last_week
  if today.sunday?
    (today - 1).to_s + LAST_SECOND
  else
    (last_sunday - 1).to_s + LAST_SECOND
  end
end

.until_next_monthObject



140
141
142
143
# File 'lib/gyunyu/command/export/custom_filter.rb', line 140

def until_next_month
  d = today >> 1
  Date.new( d.year, d.mon, -1 ).to_s + LAST_SECOND
end

.until_next_weekObject



111
112
113
# File 'lib/gyunyu/command/export/custom_filter.rb', line 111

def until_next_week
  (next_sunday + 6).to_s + LAST_SECOND
end

.until_this_monthObject



130
131
132
133
# File 'lib/gyunyu/command/export/custom_filter.rb', line 130

def until_this_month
  d = today
  Date.new( d.year, d.mon, -1 ).to_s + LAST_SECOND
end

.until_this_weekObject



103
104
105
# File 'lib/gyunyu/command/export/custom_filter.rb', line 103

def until_this_week
  (next_sunday - 1).to_s + LAST_SECOND
end

.until_todayObject



67
68
69
# File 'lib/gyunyu/command/export/custom_filter.rb', line 67

def until_today
  today.to_s + LAST_SECOND
end

.until_tomorrowObject



75
76
77
# File 'lib/gyunyu/command/export/custom_filter.rb', line 75

def until_tomorrow
  (today + 1).to_s + LAST_SECOND
end

.until_yesterdayObject



59
60
61
# File 'lib/gyunyu/command/export/custom_filter.rb', line 59

def until_yesterday
  (today - 1).to_s + LAST_SECOND
end