Class: Pomodoro::Formats::Today::TimeFrame

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pomodoro/formats/today/time_frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header:, start_time: nil, end_time: nil, task_list: Array.new, **shit) ⇒ TimeFrame

Returns a new instance of TimeFrame.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pomodoro/formats/today/time_frame.rb', line 10

def initialize(header:, start_time: nil, end_time: nil, task_list: Array.new, **shit)
  # tag, interval_from, interval_to, options = Hash.new
  @name, @tag, @options = header, nil, {}
  @interval = [start_time, end_time]
  @start_time, @end_time = start_time, end_time
  @header = header
  # @interval = [interval_from && Hour.parse(interval_from), interval_to && Hour.parse(interval_to)]
  @tasks = task_list

  # if @options.has_key?(:writeable) && ! @options[:writeable]
  #   @tasks.freeze
  # end

  unless (unrecognised_options = options.keys - ALLOWED_OPTIONS).empty?
    raise ArgumentError.new("Unrecognised options: #{unrecognised_options.inspect}")
  end
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



9
10
11
# File 'lib/pomodoro/formats/today/time_frame.rb', line 9

def end_time
  @end_time
end

#headerObject (readonly)

Returns the value of attribute header.



9
10
11
# File 'lib/pomodoro/formats/today/time_frame.rb', line 9

def header
  @header
end

#intervalObject (readonly)

Returns the value of attribute interval.



8
9
10
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8

def interval
  @interval
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8

def options
  @options
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



9
10
11
# File 'lib/pomodoro/formats/today/time_frame.rb', line 9

def start_time
  @start_time
end

#tasksObject (readonly)

Returns the value of attribute tasks.



8
9
10
# File 'lib/pomodoro/formats/today/time_frame.rb', line 8

def tasks
  @tasks
end

Instance Method Details

#active_taskObject



64
65
66
67
68
# File 'lib/pomodoro/formats/today/time_frame.rb', line 64

def active_task
  self.tasks.find do |task|
    task.in_progress?
  end
end

#create_task(header, duration = nil, tags = Array.new) ⇒ Object



28
29
30
# File 'lib/pomodoro/formats/today/time_frame.rb', line 28

def create_task(header, duration = nil, tags = Array.new)
  @tasks << Task.new(header: header, tags: tags)
end

#durationObject



87
88
89
90
91
# File 'lib/pomodoro/formats/today/time_frame.rb', line 87

def duration
  self.tasks.reduce(0) do |sum, task|
    (task.finished? && task.duration) ? sum + task.duration : sum
  end
end

#each(&block) ⇒ Object



81
82
83
84
85
# File 'lib/pomodoro/formats/today/time_frame.rb', line 81

def each(&block)
  @tasks.each do |task|
    block.call(task)
  end
end

#first_unstarted_taskObject



70
71
72
73
74
# File 'lib/pomodoro/formats/today/time_frame.rb', line 70

def first_unstarted_task
  self.tasks.find do |task|
    task.unstarted?
  end
end

#method_nameObject



56
57
58
59
60
61
62
# File 'lib/pomodoro/formats/today/time_frame.rb', line 56

def method_name
  if @name
    @name.downcase.tr(' ', '_').to_sym
  else
    :default
  end
end

#remaining_durationObject



76
77
78
# File 'lib/pomodoro/formats/today/time_frame.rb', line 76

def remaining_duration
  @interval[1] && (@interval[1] - Hour.now)
end

#to_sObject



48
49
50
51
52
53
54
# File 'lib/pomodoro/formats/today/time_frame.rb', line 48

def to_s
  if @tasks.empty?
    self.header
  else
    ["#{self.header}", self.tasks.map(&:to_s)].join("\n")
  end
end

#unshift_task(*args) ⇒ Object



32
33
34
# File 'lib/pomodoro/formats/today/time_frame.rb', line 32

def unshift_task(*args)
  @tasks.unshift(Task.new(*args))
end