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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/cats/attack-position.erb +4 -0
- data/cats/leroy.erb +5 -0
- data/cats/max.erb +1 -0
- data/lib/cat.rb +15 -18
- data/lib/catsay.rb +118 -123
- data/lib/exceptions.rb +1 -1
- data.tar.gz.sig +1 -2
- metadata +5 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0ce16df704568f8d9cb7545d1be1278cf357b32
|
4
|
+
data.tar.gz: 0b8a2904813b5b06ea49e2f334b2b81fe6e037d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c42d4e14dd81096a217c87ff71ec504af82f3e12fd94330ecbf7f81f77143f29e9e476cf6505789cdf323ff7cc973073f3ccbfd7b1174fd404d1a64280bbd08
|
7
|
+
data.tar.gz: 8f6ce384ec4657bf4a3cc7622f04e8c0c595d0b2914ce6a97dc6d5b1de17963a70403210aa1cb399c0cdd48fa9e7c00f80e0e419d1a829593f58dc3066f7044a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/cats/leroy.erb
ADDED
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
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
33
|
-
|
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
|
-
|
40
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
137
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
120
|
+
# parses the command-line arguments
|
121
|
+
def parse_arguments
|
122
|
+
options = {}
|
143
123
|
|
144
|
-
|
145
|
-
|
146
|
-
end
|
124
|
+
OptionParser.new do |opts|
|
125
|
+
opts.banner = 'usage: catsay ...'
|
147
126
|
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
154
|
-
|
155
|
-
|
131
|
+
opts.on('-o',
|
132
|
+
'--out [OUTFILE]',
|
133
|
+
'Output file (default=/dev/stdout)') do |output|
|
134
|
+
options[:output] = output
|
135
|
+
end
|
156
136
|
|
157
|
-
|
158
|
-
|
137
|
+
opts.on('-i',
|
138
|
+
'--in [INFILE]',
|
139
|
+
'Input file (default=/dev/stdin)') do |input|
|
140
|
+
options[:input] = input
|
141
|
+
end
|
159
142
|
|
160
|
-
|
143
|
+
opts.on('-l', '--list', 'List cats and exit') do |_list|
|
144
|
+
options[:list] = true
|
145
|
+
end
|
161
146
|
|
162
|
-
|
147
|
+
opts.on('-e', '--verbose', 'Annoying kitty') do |verbose|
|
148
|
+
options[:verbose] = verbose
|
149
|
+
end
|
150
|
+
end.parse!
|
163
151
|
|
164
|
-
|
165
|
-
|
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
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
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.
|
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-
|
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
|