Class: Thyme::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/thyme/format.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Format

Returns a new instance of Format.



3
4
5
# File 'lib/thyme/format.rb', line 3

def initialize(config)
  @config = config
end

Instance Method Details

#repeat_subtitleObject



21
22
23
24
25
26
27
28
29
# File 'lib/thyme/format.rb', line 21

def repeat_subtitle
  if @config.repeat == 1
    ''
  elsif @config.repeat == 0
    "(#{@config.repeat_index})"
  else
    "(#{@config.repeat_index}/#{@config.repeat})"
  end
end

#seconds_since(time) ⇒ Object



7
8
9
# File 'lib/thyme/format.rb', line 7

def seconds_since(time)
  ((DateTime.now - time) * 24 * 60 * 60).to_i
end

#time_left(seconds, min_length) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/thyme/format.rb', line 11

def time_left(seconds, min_length)
  min = (seconds / 60).floor
  lead = ' ' * [0, min_length - min.to_s.length].max
  sec = (seconds % 60).floor
  sec = "0#{sec}" if sec.to_s.length == 1
  @config.interval < 60 ?
    "#{lead}#{min}:#{sec} #{repeat_subtitle}".sub(/\s*$/, '') :
    "#{lead}#{min}m #{repeat_subtitle}".sub(/\s*$/, '')
end

#tmux_color(seconds) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/thyme/format.rb', line 31

def tmux_color(seconds)
  if @config.break
    @config.break_color
  elsif seconds < @config.warning
    @config.warning_color
  else
    'default'
  end
end