Class: Pomodoro::Schedule::DSL
- Inherits:
-
Object
- Object
- Pomodoro::Schedule::DSL
- Defined in:
- lib/pomodoro/schedule/dsl.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#schedules ⇒ Object
readonly
Returns the value of attribute schedules.
-
#today ⇒ Object
readonly
Returns the value of attribute today.
Instance Method Summary collapse
- #_require ⇒ Object
-
#initialize(schedule_dir, today = Date.today) ⇒ DSL
constructor
A new instance of DSL.
- #last_day_of_a_month ⇒ Object
- #last_work_day_of_a_month ⇒ Object
- #require(schedule) ⇒ Object
- #rule(name, condition, &block) ⇒ Object
- #schedule(name, condition, &block) ⇒ Object
Constructor Details
#initialize(schedule_dir, today = Date.today) ⇒ DSL
Returns a new instance of DSL.
32 33 34 35 |
# File 'lib/pomodoro/schedule/dsl.rb', line 32 def initialize(schedule_dir, today = Date.today) @schedule_dir, @today = schedule_dir, today @rules, @schedules = Hash.new, Hash.new end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
31 32 33 |
# File 'lib/pomodoro/schedule/dsl.rb', line 31 def rules @rules end |
#schedules ⇒ Object (readonly)
Returns the value of attribute schedules.
31 32 33 |
# File 'lib/pomodoro/schedule/dsl.rb', line 31 def schedules @schedules end |
#today ⇒ Object (readonly)
Returns the value of attribute today.
31 32 33 |
# File 'lib/pomodoro/schedule/dsl.rb', line 31 def today @today end |
Instance Method Details
#_require ⇒ Object
37 |
# File 'lib/pomodoro/schedule/dsl.rb', line 37 alias_method :_require, :require |
#last_day_of_a_month ⇒ Object
53 54 55 |
# File 'lib/pomodoro/schedule/dsl.rb', line 53 def last_day_of_a_month Date.new(today.year, today.month, -1) end |
#last_work_day_of_a_month ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/pomodoro/schedule/dsl.rb', line 57 def last_work_day_of_a_month if last_day_of_a_month.saturday? last_work_day_of_a_month = last_day_of_a_month.prev_day elsif last_day_of_a_month.sunday? last_work_day_of_a_month = last_day_of_a_month.prev_day.prev_day else last_work_day_of_a_month = last_day_of_a_month end end |
#require(schedule) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/pomodoro/schedule/dsl.rb', line 38 def require(schedule) path = File.("#{@schedule_dir}/#{schedule}.rb") self.instance_eval(File.read(path), path) rescue Errno::ENOENT # require 'pry' _require schedule end |