catsay 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a93f08365bac01b93e8543d636b01bc7e708bfd
4
- data.tar.gz: 0c4a20b991de849f16a8344616339c10dfd7ea72
3
+ metadata.gz: a0ce16df704568f8d9cb7545d1be1278cf357b32
4
+ data.tar.gz: 0b8a2904813b5b06ea49e2f334b2b81fe6e037d7
5
5
  SHA512:
6
- metadata.gz: 88752d32a7f415325ecf9019051721472a60ccaf943b873ba027ed39f5f7e061cfb0ba9c9ab476b613584968518af77e7646ca24fb13ae6018aafe0878031972
7
- data.tar.gz: 4c1373221d9d88d5c2e26fb7d42b83a2511c54da6bdfc47b996eca9eac41cdd7c4a75b12afc85d8e5a964558d36768f5d0003d8bf2c1ed9e8b714aafb1140522
6
+ metadata.gz: 6c42d4e14dd81096a217c87ff71ec504af82f3e12fd94330ecbf7f81f77143f29e9e476cf6505789cdf323ff7cc973073f3ccbfd7b1174fd404d1a64280bbd08
7
+ data.tar.gz: 8f6ce384ec4657bf4a3cc7622f04e8c0c595d0b2914ce6a97dc6d5b1de17963a70403210aa1cb399c0cdd48fa9e7c00f80e0e419d1a829593f58dc3066f7044a
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,4 @@
1
+ _._ _,-'""`-._
2
+ (,-.`._,'( |\`-/|
3
+ `-.-' \ )-`( , o o) <%= @message %>
4
+ -bf- `- \`_`"'-
data/cats/leroy.erb ADDED
@@ -0,0 +1,5 @@
1
+ <%# nosig %>
2
+ |\__/,| (`\
3
+ _.|o o |_ ) )
4
+ ---(((---(((---------
5
+ <%= @message %>
data/cats/max.erb ADDED
@@ -0,0 +1 @@
1
+ =^._.^= <%= @message %>
data/lib/cat.rb CHANGED
@@ -1,22 +1,19 @@
1
1
  module Catsay
2
+ # Cat class does the meowing.
3
+ class Cat
4
+ # create a new instance of cat
5
+ # :template specifies which template to use
6
+ # the default template is :default
7
+ def initialize(kwargs = {})
8
+ @template = kwargs[:template]
9
+ self
10
+ end
2
11
 
3
- # Cat class does the meowing.
4
- class Cat
5
-
6
- # create a new instance of cat
7
- # :template specifies which template to use
8
- # the default template is :default
9
- def initialize(kwargs = {})
10
- @template = kwargs[:template]
11
- return self
12
- end
13
-
14
- # renders the message using an erb template
15
- # returns the rendered template
16
- def meow(message)
17
- @message = message
18
- ERB.new(@template).result(binding)
12
+ # renders the message using an erb template
13
+ # returns the rendered template
14
+ def meow(message)
15
+ @message = message
16
+ ERB.new(@template).result(binding)
17
+ end
19
18
  end
20
- end
21
-
22
19
  end # module Catsay
data/lib/catsay.rb CHANGED
@@ -1,88 +1,85 @@
1
1
  require 'erb'
2
2
  require 'set'
3
3
 
4
- $:.unshift File.expand_path(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
5
5
 
6
6
  require 'cat'
7
7
  require 'exceptions'
8
8
 
9
9
  module Catsay
10
-
11
10
  # handle CLI stuff
12
11
  class CLI
13
- class << self
14
-
15
- # - parses command-line arguments
16
- # - finds the cat and makes it meow
17
- # (or gives an error)
18
- def run!
19
- @options = parse_arguments
20
-
21
- if @options[:verbose]
22
- p @options
23
- end
12
+ class << self
13
+ # - parses command-line arguments
14
+ # - finds the cat and makes it meow
15
+ # (or gives an error)
16
+ def run!
17
+ @options = parse_arguments
18
+
19
+ if @options[:verbose]
20
+ p @options
21
+ end
24
22
 
25
- # list cats and exits 0 if there are cats, 1 if not.
26
- if @options[:list]
27
- puts 'these are the cats I know:'
28
- cats.each do |cat|
29
- puts "- #{cat}"
23
+ # list cats and exits 0 if there are cats, 1 if not.
24
+ if @options[:list]
25
+ puts 'these are the cats I know:'
26
+ cats.each do |cat|
27
+ puts "- #{cat}"
28
+ end
29
+
30
+ if cats.size == 0
31
+ exit 1 # oh noes!
32
+ else
33
+ exit 0
34
+ end
30
35
  end
31
36
 
32
- if cats.size == 0
33
- exit 1 # oh noes!
34
- else
35
- exit 0
37
+ if @options[:cat] == :random
38
+ @options[:cat] = cats.to_a.sample
36
39
  end
40
+
41
+ output_handle.puts Cat.new(template: template).meow(message)
37
42
  end
38
43
 
39
- if @options[:cat] == :random
40
- @options[:cat] = cats.to_a.sample
44
+ def cats
45
+ catfiles = Dir[File.join(File.expand_path(File.dirname(__FILE__)), '..', 'cats', '*.erb')]
46
+ catfiles.map! { |x| File.basename(x, '.erb') }.to_set
41
47
  end
42
48
 
43
- output_handle.puts Cat.new(:template => template).meow(message)
44
- end
45
-
46
- def cats
47
- catfiles = Dir[File.join(File.expand_path(File.dirname(__FILE__)), '..', 'cats', '*.erb')]
48
- catfiles.map! { |x| File.basename(x, '.erb') }.to_set
49
- end
50
-
51
- private
52
-
53
- # returns a file handle for the input
54
- # if there is one or returns nil
55
- def input_handle
56
- if @options[:message] != nil
57
- nil
58
- elsif @options[:input]
59
- begin
60
- File.open(@options[:input])
61
- rescue Errno::ENOENT
62
- $stderr.puts "no such file #{@options[:input]}"
63
- exit -1
49
+ private
50
+
51
+ # returns a file handle for the input
52
+ # if there is one or returns nil
53
+ def input_handle
54
+ if !@options[:message].nil?
55
+ nil
56
+ elsif @options[:input]
57
+ begin
58
+ File.open(@options[:input])
59
+ rescue Errno::ENOENT
60
+ $stderr.puts "no such file #{@options[:input]}"
61
+ exit -1
62
+ end
63
+ else
64
+ $stdin
64
65
  end
65
- else
66
- $stdin
67
66
  end
68
- end
69
-
70
- # check if output is a string
71
- # if so, open it because that's probably a filename
72
- # otherwise, just return $stdout
73
- def output_handle
74
- if @options[:output].is_a? String
75
- File.open(@options[:output], 'w')
76
- else
77
- $stdout
67
+
68
+ # check if output is a string
69
+ # if so, open it because that's probably a filename
70
+ # otherwise, just return $stdout
71
+ def output_handle
72
+ if @options[:output].is_a? String
73
+ File.open(@options[:output], 'w')
74
+ else
75
+ $stdout
76
+ end
78
77
  end
79
- end
80
78
 
81
- # Given a symbol for a cat template, check if it
82
- # exists. If it does, return the cat template, otherwise
83
- # exits with an error
84
- def template
85
- begin
79
+ # Given a symbol for a cat template, check if it
80
+ # exists. If it does, return the cat template, otherwise
81
+ # exits with an error
82
+ def template
86
83
  heisenberg?(@options[:cat])
87
84
  rescue DeadKitty
88
85
  $stderr.puts "I haven't met a kitty named \"#{@options[:cat]}\" yet."
@@ -90,79 +87,77 @@ module Catsay
90
87
  else
91
88
  File.read(template_path_for(@options[:cat]))
92
89
  end
93
- end
94
90
 
95
- # checks if a template exists given a template id
96
- # if not, raises DeadKitty exception.
97
- def heisenberg?(cat)
98
- if File.exists? template_path_for(cat)
99
- cat
100
- else
101
- raise DeadKitty
102
- end
103
- end
104
-
105
- # returns the file path given a template id
106
- # the template id should be the name of the file
107
- # in the cats/ directory minus the cats/ and
108
- # .erb extension
109
- def template_path_for(template_id)
110
- File.join(File.expand_path(File.dirname(__FILE__)), '..', 'cats', "#{template_id}.erb")
111
- end
112
-
113
- # fetches the input by first looking for
114
- # an input handle and then looking for
115
- # options[:text] (text specified after arguments)
116
- def message
117
- if input_handle.nil?
118
- @options[:message]
119
- else
120
- input_handle.read
91
+ # checks if a template exists given a template id
92
+ # if not, raises DeadKitty exception.
93
+ def heisenberg?(cat)
94
+ if File.exist? template_path_for(cat)
95
+ cat
96
+ else
97
+ fail DeadKitty
98
+ end
121
99
  end
122
- end
123
-
124
- # parses the command-line arguments
125
- def parse_arguments
126
-
127
- options = Hash.new
128
100
 
129
- OptionParser.new do |opts|
130
- opts.banner = "usage: catsay ..."
131
-
132
- opts.on('-c', '--cat [TEMPLATE]', 'Chooses the cat.') do |cat|
133
- options[:cat] = cat.to_sym || :default
134
- end
101
+ # returns the file path given a template id
102
+ # the template id should be the name of the file
103
+ # in the cats/ directory minus the cats/ and
104
+ # .erb extension
105
+ def template_path_for(template_id)
106
+ File.join(File.expand_path(File.dirname(__FILE__)), '..', 'cats', "#{template_id}.erb")
107
+ end
135
108
 
136
- opts.on('-o', '--out [OUTFILE]', 'Output file (default=/dev/stdout)') do |output|
137
- options[:output] = output
109
+ # fetches the input by first looking for
110
+ # an input handle and then looking for
111
+ # options[:text] (text specified after arguments)
112
+ def message
113
+ if input_handle.nil?
114
+ @options[:message]
115
+ else
116
+ input_handle.read
138
117
  end
118
+ end
139
119
 
140
- opts.on('-i', '--in [INFILE]', 'Input file (default=/dev/stdin)') do |input|
141
- options[:input] = input
142
- end
120
+ # parses the command-line arguments
121
+ def parse_arguments
122
+ options = {}
143
123
 
144
- opts.on('-l', '--list', 'List cats and exit') do |list|
145
- options[:list] = true
146
- end
124
+ OptionParser.new do |opts|
125
+ opts.banner = 'usage: catsay ...'
147
126
 
148
- opts.on('-e', '--verbose', 'Annoying kitty') do |verbose|
149
- options[:verbose] = verbose
150
- end
151
- end.parse!
127
+ opts.on('-c', '--cat [TEMPLATE]', 'Chooses the cat.') do |cat|
128
+ options[:cat] = cat.to_sym || :default
129
+ end
152
130
 
153
- # check if there is a message, otherwise set message to nil
154
- message = ARGV.join(' ')
155
- options[:message] = message == "" ? nil : message
131
+ opts.on('-o',
132
+ '--out [OUTFILE]',
133
+ 'Output file (default=/dev/stdout)') do |output|
134
+ options[:output] = output
135
+ end
156
136
 
157
- # check if there is a cat template, otherwise set to :default
158
- options[:cat] = options[:cat] || :default
137
+ opts.on('-i',
138
+ '--in [INFILE]',
139
+ 'Input file (default=/dev/stdin)') do |input|
140
+ options[:input] = input
141
+ end
159
142
 
160
- return options
143
+ opts.on('-l', '--list', 'List cats and exit') do |_list|
144
+ options[:list] = true
145
+ end
161
146
 
162
- end
147
+ opts.on('-e', '--verbose', 'Annoying kitty') do |verbose|
148
+ options[:verbose] = verbose
149
+ end
150
+ end.parse!
163
151
 
164
- end # class << self
165
- end
152
+ # check if there is a message, otherwise set message to nil
153
+ message = ARGV.join(' ')
154
+ options[:message] = message == '' ? nil : message
166
155
 
156
+ # check if there is a cat template, otherwise set to :default
157
+ options[:cat] = options[:cat] || :default
167
158
 
159
+ options
160
+ end
161
+ end # class << self
162
+ end
168
163
  end
data/lib/exceptions.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Catsay
2
- class DeadKitty< Exception
2
+ class DeadKitty < Exception
3
3
  "I can't find the cat. It must be dead."
4
4
  end
5
5
  end
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- q=��mHA�:Q�;
2
- ��|��T�����2�����wmQ��4�E���V��I�ԩ��>�/��a��zh���KJ2_��={� ��Ճ@T����6��:k�����G>�Yc�ϨQXy�V��lS/]X^� 3)!MJvvb_�Uqh*��(`�����̳�}�F�)̚��`P�R��3�L��3�^�X�R-��' � ���
1
+ �,�%k��S�7p�v�9=�&C��(�,�$0u�E��5@�����X3^�қsD_�0���Uc��f�?q�� �̄f"�sD)L��ʫ��)�"��Fw>V)�'MV~�>�H�q�I��@��dl�l�Ɲ@�fg�w��1mh�|��'�V�̪����*\oK� �p�M���ߦ������ �߫G�Vl�Bsݠ������o8�Ց�\_!�����F��u%B�3h����㘚�•O���g��E�!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catsay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin G. Davis-Richardson
@@ -28,7 +28,7 @@ cert_chain:
28
28
  b9RS3+P0pRzQyo2osQTnOup3ZAlfqtG90F/m5mSIvWeJQBwcZld9X2CvJ/DgSfvX
29
29
  hArlAbz8jIiZ5FhHecQVQ6Q0sDljNdFh5N6SQp9afYfJ0Dlb
30
30
  -----END CERTIFICATE-----
31
- date: 2015-06-02 00:00:00.000000000 Z
31
+ date: 2015-06-08 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description: Like cowsay but with cats
34
34
  email: harekrishna@gmail.com
@@ -38,11 +38,14 @@ extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
40
  - bin/catsay
41
+ - cats/attack-position.erb
41
42
  - cats/default.erb
42
43
  - cats/emoji.erb
43
44
  - cats/got_dat_cat.erb
44
45
  - cats/grumpy.erb
46
+ - cats/leroy.erb
45
47
  - cats/longcat.erb
48
+ - cats/max.erb
46
49
  - cats/mini.erb
47
50
  - cats/nyancat.erb
48
51
  - cats/octocat.erb
metadata.gz.sig CHANGED
Binary file