Class: Co2Notify::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/co2-notify/notifier.rb

Constant Summary collapse

NORMALIZATION_CONSTANT =
10000.0.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Notifier

Returns a new instance of Notifier.



11
12
13
14
15
# File 'lib/co2-notify/notifier.rb', line 11

def initialize(config)
  @config = config
  @client = Co2Notify::HipchatClient.new(config)
  @status = Co2Notify::Status::Empty.new(config, Time.now)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/co2-notify/notifier.rb', line 6

def client
  @client
end

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/co2-notify/notifier.rb', line 6

def config
  @config
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/co2-notify/notifier.rb', line 6

def status
  @status
end

Class Method Details

.startObject



2
3
4
# File 'lib/co2-notify/notifier.rb', line 2

def self.start
  new(Co2Notify::Config.get).start
end

Instance Method Details

#startObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/co2-notify/notifier.rb', line 17

def start
  loop do
    time = Time.now

    if time > start_time && time < stop_time
      notify
    end

    sleep timeout * 60
  end
rescue Interrupt
end