Class: Cinch::BotTemplate::Classes::Hello

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/bot_template/classes/hello.rb

Instance Method Summary collapse

Constructor Details

#initialize(directory: Pathname('.'), shell:, options: {}) ⇒ Hello

Returns a new instance of Hello.



9
10
11
12
13
14
15
# File 'lib/cinch/bot_template/classes/hello.rb', line 9

def initialize(directory: Pathname('.'), shell:, options: {})
  @hl        = HighLine.new($stdin, $stderr, 80)
  @opts      = Hash.new { |hash, key| hash[key] = {} }
  @directory = directory
  @shell = shell
  @options   = options
end

Instance Method Details

#generateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cinch/bot_template/classes/hello.rb', line 38

def generate
  meths = self.methods.select { |x| x =~ /^get_[0-9]+_.*/ }
  meths.sort! { |m, n| m.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i <=> n.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i }
  meths.each do |m|
    self.send(m)
  end
  @hl.say "Generating..."
  tpl = Cinch::BotTemplate::Templates::Hello.new.generate(nick: @opts['bot']['nick'])
  Cinch::BotTemplate.show_wait_spinner(5) do
    if @opts.fetch('stdout', nil)
      puts tpl
    else
      filename = @opts.dig('bot', 'file')
      open filename, 'a+' do |fd|
        fd.puts tpl
      end
    end
  end
end

#get_001_bot_nameObject



18
19
20
21
# File 'lib/cinch/bot_template/classes/hello.rb', line 18

def get_001_bot_name
  @hl.say "What's the bot's name"
  @opts['bot']['nick'] = @hl.ask "    > ", String
end

#get_002_bot_fileObject

Note:

What the executable file will be named + .rb



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cinch/bot_template/classes/hello.rb', line 24

def get_002_bot_file
  @hl.say "What should the executable file be named."
  @hl.say "Use a hyphen by itself '-' to output to stdout "
  @hl.say "instead of a file."
  @hl.say "The generator will add .rb automatically."
  filename = @hl.ask "    > ", String
  if filename == '-'
    @opts['stdout'] = true
    return
  end
  @opts['bot']['file'] = filename.include?('.rb') ? filename : filename + '.rb'
end