Module: Toji::Progress::BaseProgress

Includes:
Progress
Included in:
KojiProgress, MoromiProgress, MotoProgress
Defined in:
lib/toji/progress/base_progress.rb

Instance Method Summary collapse

Instance Method Details

#all_keysObject



26
27
28
# File 'lib/toji/progress/base_progress.rb', line 26

def all_keys
  BaseState::KEYS
end

#base_timeObject



6
7
8
# File 'lib/toji/progress/base_progress.rb', line 6

def base_time
  states&.first&.time&.to_time
end

#day_labelsObject



22
23
24
# File 'lib/toji/progress/base_progress.rb', line 22

def day_labels
  days.times.map(&:succ).map(&:to_s)
end

#day_offsetObject



10
11
12
13
14
15
16
# File 'lib/toji/progress/base_progress.rb', line 10

def day_offset
  t = base_time
  if t
    offset = (t - Time.mktime(t.year, t.month, t.day)).to_i
    (DAY -  + offset) % DAY
  end
end

#daysObject



18
19
20
# File 'lib/toji/progress/base_progress.rb', line 18

def days
  ((states&.last&.elapsed_time_with_offset&.to_f + 1) / DAY).ceil
end

#has_keysObject



30
31
32
33
34
# File 'lib/toji/progress/base_progress.rb', line 30

def has_keys
  all_keys.select {|k|
    states.find {|s| s.send(k).present?}
  }
end