class Barabara::Modules::Clock

Attributes

time[R]

Public Class Methods

new() click to toggle source
# File lib/barabara/modules/clock.rb, line 6
def initialize
  config = GlobalConfig.config.module_config('clock')
  colors = GlobalConfig.config.colors
  @format = format(config['format'], colors) || '%F %R'
  @time = Time.now
end

Public Instance Methods

watch() click to toggle source
# File lib/barabara/modules/clock.rb, line 15
def watch
  loop do
    update
    push
    sleep 5
  end
end

Private Instance Methods

push() click to toggle source
# File lib/barabara/modules/clock.rb, line 25
def push
  publish(:event, 'time', render)
end
render() click to toggle source
# File lib/barabara/modules/clock.rb, line 33
def render
  @time.strftime(@format)
end
update() click to toggle source
# File lib/barabara/modules/clock.rb, line 29
def update
  @time = Time.now
end