Class: Catsay::CLI
- Inherits:
-
Object
- Object
- Catsay::CLI
- Defined in:
- lib/catsay.rb
Overview
handle CLI stuff
Class Method Summary collapse
- .catfiles ⇒ Object
- .cats ⇒ Object
-
.run! ⇒ Object
-
parses command-line arguments - finds the cat and makes it meow (or gives an error).
-
Class Method Details
.catfiles ⇒ Object
44 45 46 |
# File 'lib/catsay.rb', line 44 def catfiles @catfiles ||= Dir.glob(File.join(File.(File.dirname(__FILE__)), '..', 'cats', '*.erb')) end |
.cats ⇒ Object
48 49 50 |
# File 'lib/catsay.rb', line 48 def cats catfiles.map! { |x| File.basename(x, '.erb') }.to_set end |
.run! ⇒ Object
-
parses command-line arguments
-
finds the cat and makes it meow (or gives an error)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/catsay.rb', line 16 def run! @options = parse_arguments if @options[:verbose] p @options end # list cats and exits 0 if there are cats, 1 if not. if @options[:list] puts 'these are the cats I know:' cats.each do |cat| puts "- #{cat}" end if cats.size == 0 exit 1 # oh noes! else exit 0 end end if @options[:cat] == :random @options[:cat] = cats.to_a.sample end output_handle.puts Cat.new(template: template).meow() end |