Class: Pomodoro::Formats::Today::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/pomodoro/formats/today/day.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, nodes: Array.new) ⇒ Day

Returns a new instance of Day.


17
18
19
# File 'lib/pomodoro/formats/today/day.rb', line 17

def initialize(path: nil, nodes: Array.new)
  @path, @nodes = path, nodes
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path


16
17
18
# File 'lib/pomodoro/formats/today/day.rb', line 16

def path
  @path
end

#task_listObject (readonly)

Returns the value of attribute task_list


16
17
18
# File 'lib/pomodoro/formats/today/day.rb', line 16

def task_list
  @task_list
end

Class Method Details

.for(date) ⇒ Object


10
11
12
13
14
# File 'lib/pomodoro/formats/today/day.rb', line 10

def self.for(date)
  path = Pomodoro.config.today_path(date)
  Pomodoro::Formats::Today.parse(File.open(path, encoding: 'utf-8'))
rescue Errno::ENOENT
end

Instance Method Details

#dateObject


21
22
23
# File 'lib/pomodoro/formats/today/day.rb', line 21

def date
  Date.parse(self.path.match(/\d{4}-\d{2}-\d{2}/)[0]) if self.path
end

#empty?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'lib/pomodoro/formats/today/day.rb', line 49

def empty?
  self.tags.empty? && self.task_list.time_frames.empty?
end

#normal?Boolean

Returns:

  • (Boolean)

53
54
55
# File 'lib/pomodoro/formats/today/day.rb', line 53

def normal?
  ([:holidays, :bedbound] & self.tags).empty?
end

#reviewObject

TODO: And now it doesn't belong to today anymore.


42
43
44
45
46
47
# File 'lib/pomodoro/formats/today/day.rb', line 42

def review
  path = self.path #|| Pomodoro.config.today_path # FIXME: This is just for now, it doesn't work since it just takes today path.
  review_path = path.sub('.today', '_review.md')
  Pomodoro::Formats::Review.parse(File.new(review_path, encoding: 'utf-8'))
rescue Errno::ENOENT
end

#save(path) ⇒ Object


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

def save(path)
  data = self.to_s
  File.open(path, 'w:utf-8') do |file|
    file.puts(data)
  end
end

#tagsObject


25
26
27
28
29
30
31
# File 'lib/pomodoro/formats/today/day.rb', line 25

def tags
  @tags ||= if @nodes.first.is_a?(TimeFrame) || @nodes.first.nil?
    Array.new
  else
    @nodes.first[:tags]
  end
end

#to_sObject


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

def to_s
  header = self.tags.map { |tag| "@#{tag}" }.join(' ')
  [(header unless tags.empty?), self.task_list].compact.join("\n\n")
end