Class: Pomodoro::Schedule::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/pomodoro/schedule/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rulesObject (readonly)

Returns the value of attribute rules.



31
32
33
# File 'lib/pomodoro/schedule/dsl.rb', line 31

def rules
  @rules
end

#schedulesObject (readonly)

Returns the value of attribute schedules.



31
32
33
# File 'lib/pomodoro/schedule/dsl.rb', line 31

def schedules
  @schedules
end

#todayObject (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

#_requireObject



37
# File 'lib/pomodoro/schedule/dsl.rb', line 37

alias_method :_require, :require

#last_day_of_a_monthObject



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_monthObject



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.expand_path("#{@schedule_dir}/#{schedule}.rb")
  self.instance_eval(File.read(path), path)
rescue Errno::ENOENT # require 'pry'
  _require schedule
end

#rule(name, condition, &block) ⇒ Object



49
50
51
# File 'lib/pomodoro/schedule/dsl.rb', line 49

def rule(name, condition, &block)
  @rules[name] = Rule.new(condition, &block)
end

#schedule(name, condition, &block) ⇒ Object



45
46
47
# File 'lib/pomodoro/schedule/dsl.rb', line 45

def schedule(name, condition, &block)
  @schedules[name] = Schedule.new(condition, &block)
end