le_meme 0.0.2 → 0.0.3

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: 8edb5a713ef3cd54d149ef5af9439b9b9f94e79f
4
- data.tar.gz: 124d701e04dd8b9c6ecbde089d77875e213291d1
3
+ metadata.gz: 66f7f3d32fc6267a4bedde418374d413bd9638e0
4
+ data.tar.gz: 8a8cbcd49e5dc42a5dbb41477149fa4364145c97
5
5
  SHA512:
6
- metadata.gz: fa885045027ea3caa0ab6180a14ec8ba3e6ced0a12c5f1edf9026d14915c89d64d5ccbf6063e6cb39297a0e3f0a7f7bf51472971871fffd2b05361da8ec25692
7
- data.tar.gz: b702ef9aa209cda2c9805867f959cc05d3a39c4d6f2500727026231be54c8ba2558ec049b0970abfda036b62f550cb87c40b4cd82e58b631c77f2e83a674b219
6
+ metadata.gz: 6b022383b8dc44d85a43886520ae3da88e50e64fc8bd6f0f27effed9d10f3d5a051c4fa67974ffec1f1eb029a165be9bcfb4a324a983aedeb433c3b50ecfb367
7
+ data.tar.gz: dca9ac81f463c1e880ecd5f685d7e1447f8b045e4637886fb063532906d3afba401051b0685beb7fed98a780b9b023ba7c58269164442ceda1ab778fbaf90529
data/README.md CHANGED
@@ -60,7 +60,7 @@ Actually, because I wanted to take some time and clean up the core of [memebot](
60
60
 
61
61
  ## TODO
62
62
  - [ ] Test suite
63
- - [ ] Accept non-tmp dir meme generation paths
63
+ - [ ] Allow dynamic additon of memes to internal memecache
64
64
 
65
65
  ## License
66
66
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ['--color', '--format', 'd']
6
+ end
7
+
8
+ task :default => :spec
data/bin/meme CHANGED
@@ -19,6 +19,7 @@ HEREDOC
19
19
  on 'm', 'meme=', 'meme template you want to use, see --templates'
20
20
  on 'p', 'path=', 'path to an image to use for the meme'
21
21
  on 'w', 'watermark=', 'text to watermark the image'
22
+ on 'o', 'outpath=', 'path to save the final meme to'
22
23
 
23
24
  on 'templates', 'list all the meme templates' do
24
25
  puts memegen.memes.keys.join("\n")
@@ -34,5 +35,9 @@ end
34
35
  top = opts[:top] || ARGV[0]
35
36
  bottom = opts[:bottom] || ARGV[1]
36
37
 
37
- $stdout.puts memegen.fast_meme(name: opts[:meme], top: top, bottom: bottom, watermark: opts[:watermark])
38
+ if opts[:path]
39
+ $stdout.puts memegen.meme(path: opts[:path], top: top, bottom: bottom, watermark: opts[:watermark], outpath: opts[:outpath])
40
+ else
41
+ $stdout.puts memegen.fast_meme(name: opts[:meme], top: top, bottom: bottom, watermark: opts[:watermark], outpath: opts[:outpath])
42
+ end
38
43
  exit
data/le_meme.gemspec CHANGED
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'le_meme/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "le_meme"
7
+ spec.name = 'le_meme'
8
8
  spec.version = LeMeme::VERSION
9
- spec.authors = ["Jeff Sandberg"]
10
- spec.email = ["paradox460@gmail.com"]
11
- spec.summary = %q{Dank memes, in gem form}
12
- spec.description = %q{A gem that generates memes. Can be used as a library or command-line executable.}
13
- spec.homepage = "http://github.com/paradox460/le_meme"
14
- spec.license = "MIT"
9
+ spec.authors = ['Jeff Sandberg']
10
+ spec.email = ['paradox460@gmail.com']
11
+ spec.summary = 'Dank memes, in gem form'
12
+ spec.description = 'A gem that generates memes. Can be used as a library or command-line executable.'
13
+ spec.homepage = 'http://github.com/paradox460/le_meme'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "pry", "~> 0.10"
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'pry', '~> 0.10'
24
+ spec.add_development_dependency 'rspec', '~> 3.1'
24
25
 
25
26
  spec.add_runtime_dependency 'rmagick', '~> 2.13'
26
27
  spec.add_runtime_dependency 'word_wrapper', '~> 0.5.0'
@@ -1,3 +1,3 @@
1
1
  class LeMeme
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/le_meme.rb CHANGED
@@ -28,8 +28,9 @@ class LeMeme
28
28
  # @param top [String] The text you want to appear on the top of the meme.
29
29
  # @param bottom [String] The text you want to appear on the bottom of the meme.
30
30
  # @param watermark [String] The watermark text. If nil it is omitted
31
+ # @param outpath [String] Where do you want to put the generated meme. Defaults to /tmp/
31
32
  # @return [String] Path to the generated meme
32
- def generate(path:, top: nil, bottom: nil, watermark: nil)
33
+ def generate(path:, top: nil, bottom: nil, watermark: nil, outpath: nil)
33
34
  top = (top || '').upcase
34
35
  bottom = (bottom || '').upcase
35
36
 
@@ -54,7 +55,7 @@ class LeMeme
54
55
  end
55
56
  end
56
57
 
57
- output_path = "/tmp/meme-#{Time.now.to_i}#{path.extname}"
58
+ output_path = outpath || "/tmp/meme-#{Time.now.to_i}#{path.extname}"
58
59
  canvas.write(output_path)
59
60
  output_path
60
61
  end
@@ -67,8 +68,9 @@ class LeMeme
67
68
  # @param top [String] The text you want to appear on the top of the meme.
68
69
  # @param bottom [String] The text you want to appear on the bottom of the meme.
69
70
  # @param watermark [String] The watermark text. If nil it is omitted
71
+ # @param outpath [String] Where do you want to put the generated meme. Defaults to /tmp/
70
72
  # @return [String] Path to the generated meme
71
- def fast_meme(name: nil, top: nil, bottom: nil, watermark: nil)
73
+ def fast_meme(name: nil, top: nil, bottom: nil, watermark: nil, outpath: nil)
72
74
  if name.nil?
73
75
  path = @memes[@memes.keys.sample]
74
76
  elsif @memes[name].nil?
@@ -76,7 +78,7 @@ class LeMeme
76
78
  else
77
79
  path = @memes[name]
78
80
  end
79
- generate(path: path, top: top, bottom: bottom, watermark: watermark)
81
+ generate(path: path, top: top, bottom: bottom, watermark: watermark, outpath: outpath)
80
82
  end
81
83
  alias_method :m, :fast_meme
82
84
 
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe LeMeme do
4
+ let(:meme) { LeMeme.new }
5
+
6
+ describe '#generate' do
7
+ let(:image) { File.join(File.dirname(File.expand_path(__FILE__)), '../memes/maymay.jpg') }
8
+ context 'without an image path' do
9
+ it 'should raise ArgumentError with "missing keyword: path"' do
10
+ expect { meme.generate }.to raise_error(ArgumentError, 'missing keyword: path')
11
+ end
12
+ end
13
+ context 'with an image path' do
14
+ x = ['text', nil] * 3
15
+ x.permutation(3).to_a.uniq.each do |top, bottom, watermark|
16
+ it "should generate a meme with top: '#{top}', bottom: '#{bottom}', and watermark: '#{watermark}'" do
17
+ expect(meme.generate(path: image, top: top, bottom: bottom, watermark: watermark)).to match(%r{/tmp/meme-\d+.jpg})
18
+ end
19
+ end
20
+ end
21
+ context 'with an outpath' do
22
+ it 'should generate a meme at the specified outpath' do
23
+ expect_any_instance_of(Magick::ImageList).to receive(:write).and_return('test.jpg')
24
+ expect(meme.generate(path: image, top: 'top', bottom: 'bottom', outpath: 'test.jpg')).to eq('test.jpg')
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#meme' do
30
+ it 'should be an alias of #generate' do
31
+ expect(meme.method(:meme)).to eq(meme.method(:generate))
32
+ end
33
+ end
34
+
35
+ describe '#fast_meme' do
36
+ let(:template) { 'maymay' }
37
+ it 'should pass its params to generate_meme' do
38
+ expect(meme).to receive(:generate) do |args|
39
+ expect(args[:path]).to eq(Pathname.new('/Users/jeffsandberg/Developer/le_meme/memes/maymay.jpg'))
40
+ expect(args[:top]).to eq('top text')
41
+ expect(args[:bottom]).to eq('bottom text')
42
+ expect(args[:watermark]).to eq('watermark')
43
+ expect(args[:outpath]).to eq('outpath')
44
+ end
45
+ meme.fast_meme(name: template, top: 'top text', bottom: 'bottom text', watermark: 'watermark', outpath: 'outpath')
46
+ end
47
+
48
+ context 'without a specified template' do
49
+ it 'should generate a meme' do
50
+ expect(meme.fast_meme).to match(%r{/tmp/meme-\d+.jpg})
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#m' do
56
+ it 'should be an alias of #fast_meme' do
57
+ expect(meme.method(:m)).to eq(meme.method(:fast_meme))
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,6 @@
1
+ require 'pry'
2
+ require 'le_meme'
3
+
4
+ RSpec.configure do |c|
5
+ c.raise_errors_for_deprecations!
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: le_meme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandberg
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rmagick
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -195,6 +209,8 @@ files:
195
209
  - memes/yee.jpg
196
210
  - memes/yuno.jpg
197
211
  - open
212
+ - spec/le_meme_spec.rb
213
+ - spec/spec_helper.rb
198
214
  homepage: http://github.com/paradox460/le_meme
199
215
  licenses:
200
216
  - MIT
@@ -219,5 +235,6 @@ rubygems_version: 2.4.5
219
235
  signing_key:
220
236
  specification_version: 4
221
237
  summary: Dank memes, in gem form
222
- test_files: []
223
- has_rdoc:
238
+ test_files:
239
+ - spec/le_meme_spec.rb
240
+ - spec/spec_helper.rb