Class: Battlecry

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

Overview

Battlecry is a simply abstraction for sending growl messages to many hosts (allies)

See growl.info/

depends on the ruby-growl gem gem install ruby-growl

Allies must have OSX installed and must listen for incoming notifcations to hear the cry. You can enable this by going to the Growl configuration panel under System Preferences. Go to the network tab and check the following boxes

  • Listen for incoming notifications

  • Allow remote application registration

Example

battlecry = Battlecry.new [{
  :host => "localhost"
},{
  :host => "myhost.com",
  :password => "test"
}]
battlecry.shout "We will defeat our enemies!"

Constant Summary collapse

VERSION =
0.2

Instance Method Summary collapse

Constructor Details

#initialize(allies) ⇒ Battlecry

Creates a Battlecry, which registers notificaitons with one or more remote machines, known as allies

allies is an array of allies which will be affected by a battlecry. An ally is a hash object with a :host param (hostname), and an optional :password param eg: { :host => “localhost”, :password => “password” }



44
45
46
47
48
49
# File 'lib/battlecry.rb', line 44

def initialize allies
  @allies = []
  allies.each do |ally|
    add_ally ally[:host], ally[:password]
  end
end

Instance Method Details

#add_ally(host, password = nil) ⇒ Object

Adds an ally to the army

host the hostname of the ally

title the password for the ally



73
74
75
# File 'lib/battlecry.rb', line 73

def add_ally host, password = nil
  @allies << Growl.new(host, "battlecry", ["battlecry"], nil, password)
end

#num_alliesObject

The size of the army



79
80
81
# File 'lib/battlecry.rb', line 79

def num_allies
  @allies.size
end

#shout(message, title = "Battlecry", priority = 0, sticky = false) ⇒ Object

Battlecrys for all allies in the army

message the content of the battlecry

title the title, or context of the battlecry

priority the intensity of the cry from -2 to 2

sticky makes the cry stick in the heads of allies



61
62
63
64
65
# File 'lib/battlecry.rb', line 61

def shout message, title = "Battlecry", priority = 0, sticky = false
  @allies.each do |ally|
    ally.notify "battlecry", title, message, priority, sticky
  end
end