Class: Roast::Main

Inherits:
Object show all
Includes:
Tinder
Defined in:
lib/roast/main.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Main

Returns a new instance of Main.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/roast/main.rb', line 8

def initialize(options)
  @message = options[:message]      
  @config = YAML.load_file(ENV['HOME'] + '/roast.yml')
  room_config = @config[(options[:room] ? options[:room].to_s : @config["default"])]
  @room = room_config['room']
  @domain = room_config['domain']
  @ssl = room_config['ssl']
  @username = room_config['username']
  @password = room_config['password']
  @verbose = options[:verbose]
  self
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/roast/main.rb', line 6

def config
  @config
end

#domainObject

Returns the value of attribute domain.



6
7
8
# File 'lib/roast/main.rb', line 6

def domain
  @domain
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/roast/main.rb', line 6

def message
  @message
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/roast/main.rb', line 6

def password
  @password
end

#roomObject

Returns the value of attribute room.



6
7
8
# File 'lib/roast/main.rb', line 6

def room
  @room
end

#sslObject

Returns the value of attribute ssl.



6
7
8
# File 'lib/roast/main.rb', line 6

def ssl
  @ssl
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/roast/main.rb', line 6

def username
  @username
end

#verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/roast/main.rb', line 6

def verbose
  @verbose
end

Class Method Details

.run(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/roast/main.rb', line 21

def self.run(options={})
  
  opts = OptionParser.new do |opt|
    opt.banner = "Usage: roast [options] message"
    opt.separator ""
    opt.separator "Specific options:"

    opt.on("-r", "--room [room config]",
               "Room name from config") do |room|
      options[:room] = room
    end
    opt.on("-v", "--verbose",
               "Be verbose during the posting of the message") do |verbose|
      options[:verbose] = true
    end
  end

  opts.parse!(ARGV)

  roast = Roast::Main.new(options)

  roast.vocalize "Using #{roast.room} configuration ..."

  campfire = Campfire.new(roast.domain, :ssl => roast.ssl)

  roast.vocalize "Logging in..."
  campfire.(roast.username, roast.password)
  roast.vocalize "Logged in!"

  room = campfire.find_room_by_name(roast.room)

  roast.vocalize "Joining #{room.name}..."
  roast.vocalize "Entered room #{room.name}"

  roast.vocalize "Saying message..."

  if message_long?(options[:message])
    room.paste(options[:message])
  else
    room.speak(options[:message])
  end

  roast.vocalize "Leaving room..."

  roast.vocalize "Done."
end

Instance Method Details

#vocalize(message) ⇒ Object



68
69
70
# File 'lib/roast/main.rb', line 68

def vocalize(message)
  STDOUT.puts message if self.verbose
end