Module: TaskLoop::TaskProperty

Included in:
Task
Defined in:
lib/taskloop/task/task_property.rb

Constant Summary collapse

WEEK =
{
  :Sun       => 0,
  :Mon       => 1,
  :Tue       => 2,
  :Wed       => 3,
  :Thu       => 4,
  :Fri       => 5,
  :Sat       => 6,
}
MONTH =
{
  :Jan       => 1,
  :Feb       => 2,
  :Mar       => 3,
  :Apr       => 4,
  :Jun       => 6,
  :Jul       => 7,
  :Aug       => 8,
  :Sep       => 9,
  :Oct       => 10,
  :Nov       => 11,
  :Dec       => 12,
  :mon1      => 1,
  :mon2      => 2,
  :mon3      => 3,
  :mon4      => 4,
  :mon5      => 5,
  :mon6      => 6,
  :mon7      => 7,
  :mon8      => 8,
  :mon9      => 9,
  :mon10     => 10,
  :mon11     => 11,
  :mon12     => 12,
}
DAY =
{
  :day1      => 1,
  :day2      => 2,
  :day3      => 3,
  :day4      => 4,
  :day5      => 5,
  :day6      => 6,
  :day7      => 7,
  :day8      => 8,
  :day9      => 9,
  :day10     => 10,
  :day11     => 11,
  :day12     => 12,
  :day13     => 13,
  :day14     => 14,
  :day15     => 15,
  :day16     => 16,
  :day17     => 17,
  :day18     => 18,
  :day19     => 19,
  :day20     => 20,
  :day21     => 21,
  :day22     => 22,
  :day23     => 23,
  :day24     => 24,
  :day25     => 25,
  :day26     => 26,
  :day27     => 27,
  :day28     => 28,
  :day29     => 29,
  :day30     => 30,
  :day31     => 31,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

the name of task



74
75
76
# File 'lib/taskloop/task/task_property.rb', line 74

def name
  @name
end

#pathObject

the path of task



76
77
78
# File 'lib/taskloop/task/task_property.rb', line 76

def path
  @path
end

Instance Method Details

#dateObject



294
295
296
# File 'lib/taskloop/task/task_property.rb', line 294

def date
  @date ||= DefaultRule.new(:date)
end

#date=(rule) ⇒ Object

Date Property date list syntax

- date
  - example: date "2023-10-10", "2013-10-11", "2023-11-10"


286
287
288
289
290
291
292
293
# File 'lib/taskloop/task/task_property.rb', line 286

def date=(rule)
  unless rule.is_a?(DateListRule)
    raise TypeError, "the rule of time must be DateListRule"
  end

  @date = rule
  @date.unit = :date
end

#dayObject



185
186
187
# File 'lib/taskloop/task/task_property.rb', line 185

def day
  @day ||= DefaultRule.new(:day)
end

#day=(rule) ⇒ Object

Day Property specific syntax

- at
  - example: at :day1, :day2, :day3 ...

interval syntax

- interval
  - example: interval 10.day

scope syntax

- before
  - example: before :day10
- between
  - example: between :day10, :day19
  - example: between :Mon, :Fri
- after
  - example: after :day10


177
178
179
180
181
182
183
# File 'lib/taskloop/task/task_property.rb', line 177

def day=(rule)
  unless rule.is_a?(SpecificRule) || rule.is_a?(ScopeRule) || rule.is_a?(IntervalRule)
    raise TypeError, "the rule of day must be SpecificRule or ScopeRule or IntervalRule"
  end
  @day = rule
  @day.unit = :day
end

#end_pointObject



330
331
332
# File 'lib/taskloop/task/task_property.rb', line 330

def end_point
  @end_point ||= DefaultRule.new(:full)
end

#end_point=(rule) ⇒ Object

EndPoint Property boundary syntax

- end_point
  - example: to "2023-10-11 10:00:00"


322
323
324
325
326
327
328
# File 'lib/taskloop/task/task_property.rb', line 322

def end_point=(rule)
  unless rule.is_a?(EndPointBoundaryRule)
    raise TypeError, "the rule of end_point must be EndPointBoundaryRule"
  end
  @end_point = rule
  @end_point.unit = :full
end

#has_date?Boolean

Returns:

  • (Boolean)


340
341
342
# File 'lib/taskloop/task/task_property.rb', line 340

def has_date?
  !date.is_a?(DefaultRule)
end

#has_hm?Boolean

Returns:

  • (Boolean)


352
353
354
# File 'lib/taskloop/task/task_property.rb', line 352

def has_hm?
  [hour, minute].any? { |rule| !rule.is_a?(DefaultRule) }
end

#has_interval_rule?Boolean

Returns:

  • (Boolean)


356
357
358
359
# File 'lib/taskloop/task/task_property.rb', line 356

def has_interval_rule?
  rules = [year, month, day, hour, minute]
  return rules.any?{ |rule| rule.is_a?(IntervalRule) }
end

#has_time?Boolean

Returns:

  • (Boolean)


344
345
346
# File 'lib/taskloop/task/task_property.rb', line 344

def has_time?
  !time.is_a?(DefaultRule)
end

#has_week?Boolean

Help Methods

Returns:

  • (Boolean)


337
338
339
# File 'lib/taskloop/task/task_property.rb', line 337

def has_week?
  !week.is_a?(DefaultRule)
end

#has_ymd?Boolean

Returns:

  • (Boolean)


348
349
350
# File 'lib/taskloop/task/task_property.rb', line 348

def has_ymd?
  [year, month, day].any? { |rule| !rule.is_a?(DefaultRule) }
end

#hourObject



213
214
215
# File 'lib/taskloop/task/task_property.rb', line 213

def hour
  @hour ||= DefaultRule.new(:hour)
end

#hour=(rule) ⇒ Object

Hour Property specific syntax

- at
  - example: at 10, 11, 13 ...

interval syntax

- interval
  - example: interval 10.hour

scope syntax

- before
  - example: before 9
- between
  - example: between 10, 12
- after
  - example: after 11


205
206
207
208
209
210
211
# File 'lib/taskloop/task/task_property.rb', line 205

def hour=(rule)
  unless rule.is_a?(SpecificRule) || rule.is_a?(ScopeRule) || rule.is_a?(IntervalRule)
    raise TypeError, "the rule of hour must be SpecificRule or ScopeRule or IntervalRule"
  end
  @hour = rule
  @hour.unit = :hour
end

#last_timeObject



369
370
371
372
373
374
375
# File 'lib/taskloop/task/task_property.rb', line 369

def last_time
  timestamp = 0
  File.open(timefile_path, 'r') do |file|
    timestamp = file.gets.to_i
  end
  return Time.at(timestamp)
end

#loopObject



258
259
260
# File 'lib/taskloop/task/task_property.rb', line 258

def loop
  @loop ||= DefaultRule.new(:loop)
end

#loop=(rule) ⇒ Object

Loop Property loop syntax

- loop
  - example: loop 5.times


250
251
252
253
254
255
256
257
# File 'lib/taskloop/task/task_property.rb', line 250

def loop=(rule)
  unless rule.is_a?(LoopRule)
    raise TypeError, "the rule of loop must be LoopRule"
  end

  @loop = rule
  @loop.unit = :loop
end

#loop_countObject



361
362
363
364
365
366
367
# File 'lib/taskloop/task/task_property.rb', line 361

def loop_count
  count = 0
  File.open(loopfile_path, 'r') do |file|
    count = file.gets.to_i
  end
  return count
end

#minuteObject



240
241
242
# File 'lib/taskloop/task/task_property.rb', line 240

def minute
  @minute ||= DefaultRule.new(:minute)
end

#minute=(rule) ⇒ Object

Minute Property specific syntax

- at
  - example: at 59, 23 ...

interval syntax

- interval
  - example: interval 5.minute

scope syntax

- before
  - example: before 9
- between
  - example: between 10, 12
- after
  - example: after 11


232
233
234
235
236
237
238
# File 'lib/taskloop/task/task_property.rb', line 232

def minute=(rule)
  unless rule.is_a?(SpecificRule) || rule.is_a?(ScopeRule)  || rule.is_a?(IntervalRule)
    raise TypeError, "the rule of minute must be SpecificRule or ScopeRule or IntervalRule"
  end
  @minute = rule
  @minute.unit = :minute
end

#monthObject



156
157
158
# File 'lib/taskloop/task/task_property.rb', line 156

def month
  @month||= DefaultRule.new(:month)
end

#month=(rule) ⇒ Object

Month Property specific syntax

- at
  - example: at :Jan, :Feb, :Mar, :Apr, :Jun, :Jul, :Aug, :Sep, :Oct, :Nov, :Dec;
  - example: at :month1, :month2, :month3 ...

interval syntax

- every
  - example: interval 1.month

scope syntax

- before
  - example: before 2025
- between
  - example: between 2025, 2026
- after
  - examle: after 2023


148
149
150
151
152
153
154
# File 'lib/taskloop/task/task_property.rb', line 148

def month=(rule)
  unless rule.is_a?(SpecificRule) || rule.is_a?(ScopeRule) || rule.is_a?(IntervalRule)
    raise TypeError, "the rule of month must be SpecificRule or ScopeRule or IntervalRule"
  end
  @month = rule
  @month.unit = :month
end

#start_pointObject



312
313
314
# File 'lib/taskloop/task/task_property.rb', line 312

def start_point
  @start_point ||= DefaultRule.new(:full)
end

#start_point=(rule) ⇒ Object

StartPoint Property boundary syntax

- start_point
  - example: from "2023-10-11 10:00:00"


304
305
306
307
308
309
310
# File 'lib/taskloop/task/task_property.rb', line 304

def start_point=(rule)
  unless rule.is_a?(StartPointBoundaryRule)
    raise TypeError, "the rule of start_point must be StartPointBoundaryRule"
  end
  @start_point = rule
  @start_point.unit = :full
end

#timeObject



276
277
278
# File 'lib/taskloop/task/task_property.rb', line 276

def time
  @time ||= DefaultRule.new(:time)
end

#time=(rule) ⇒ Object

Time Property time list syntax

- time
  - example: time "10:10:30", "9:10:20", "20:10:20"


268
269
270
271
272
273
274
275
# File 'lib/taskloop/task/task_property.rb', line 268

def time=(rule)
  unless rule.is_a?(TimeListRule)
    raise TypeError, "the rule of time must be TimeListRule"
  end

  @time = rule
  @time.unit = :time
end

#weekObject



99
100
101
# File 'lib/taskloop/task/task_property.rb', line 99

def week
  @week ||= DefaultRule.new(:week)
end

#week=(rule) ⇒ Object

Week Property specific syntax

- at
  - example: at :Mon, :Tue, :Fri

scope syntax

- before
  - example: before :Mon
- between
  - example: between :Mon, :Fri
- after
  0 example: after :Tue


91
92
93
94
95
96
97
# File 'lib/taskloop/task/task_property.rb', line 91

def week=(rule)
  unless rule.is_a?(SpecificRule) || rule.is_a?(ScopeRule)
    raise TypeError, "the rule of week must be SpecificRule or ScopeRule or IntervalRule"
  end
  @week = rule
  @week.unit = :week
end

#yearObject



127
128
129
# File 'lib/taskloop/task/task_property.rb', line 127

def year
  @year ||= DefaultRule.new(:year)
end

#year=(rule) ⇒ Object

Year Property specific syntax

- of
  - example: at 2024, 2025 ...

interval syntax

- interval
  - example: interval 1.year

scope syntax

- before
  - example: before 2025
- between
  - example: between 2025, 2026
- after
  - example: after 2023


119
120
121
122
123
124
125
# File 'lib/taskloop/task/task_property.rb', line 119

def year=(rule)
  unless rule.is_a?(SpecificRule) || rule.is_a?(ScopeRule) || rule.is_a?(IntervalRule)
    raise TypeError, "the rule of year must be SpecificRule or ScopeRule or IntervalRule"
  end
  @year = rule
  @year.unit = :year
end