Class: CrazyDoll::Wizard

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Wizard

Returns a new instance of Wizard.



3
4
5
6
# File 'lib/crazy_doll/wizard.rb', line 3

def initialize(config)
  @config = config
  run
end

Instance Method Details

#get(string, default = nil, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/crazy_doll/wizard.rb', line 35

def get(string, default=nil, &block)
  print string << " "
  g = gets.chomp
  g = default if g.empty?
  if g and block_given?
    return yield g      
  end
  g
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/crazy_doll/wizard.rb', line 8

def run
  @config.register(self,
                   :server,
                   'Address of IRC server',
                   get("Type the address of server(i.e. irc.freenode.net):", 'irc.freenode.net')) unless @config.respond_to?(:server) and @config.server.is_a?(String)
  @config.register(self,
                   :port,
                   'The port of IRC server',
                   get("Type the port of server(default 6667):", 6667){|x| Integer(x) rescue 6667 }) unless @config.respond_to?(:port) and @config.port.is_a?(Integer)

  unless @config.respond_to?(:nick) and @config.nick.is_a?(OpenStruct) and @config.nick.name and not @config.nick.name.empty?
    @config.register(self, :nick, 'Info(nick, user, name, password) of bot', OpenStruct.new({
      :name => get("Type the nick of bot(default CrazyDoll):", 'CrazyDoll') { |x| x.empty? ? 'CrazyDoll' : x },
      :user => get("Type the user of bot(default CrazyBot):", 'CrazyBot') { |x| x.empty? ? 'CrazyBot' : x },
      :real_name => get("Type the 'real name' of bot(default CrazyDoll #{CrazyDoll::VERSION}):",
                        "CrazyDoll #{CrazyDoll::VERSION}") { |x| x.empty? ? "CrazyDoll #{CrazyDoll::VERSION}" : x },
      :password  => get("Type the password of bot(default not use):", nil) { |x| x.empty? ? nil : x }
    }))
  end

  @config.register(self,
                   :channels,
                   'Channels to join',
                   get("Type the channels to enter separed by comma(i.e. #crazydoll,#ubuntugames):", "#crazydoll") { |chans|
    chans.gsub(' ','').split(',') }) unless @config.respond_to?(:channels) and @config.channels.is_a?(Array) and not @config.channels.empty?
end