Top Level Namespace

Defined Under Namespace

Classes: MemeGenerator

Instance Method Summary collapse

Instance Method Details

#generate(path, top, bottom, campfire, groupme) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/meme_generator/cli.rb', line 31

def generate(path, top, bottom, campfire, groupme)
  if top || bottom
    output_path = MemeGenerator.generate(path, top, bottom)

    if campfire
      MemeGenerator::Campfire.upload(output_path)
    end
    if groupme
      MemeGenerator::GroupMe.upload(output_path)
    end
    if (! (campfire || groupme) )
      puts output_path
    end
    exit 0
  else
    puts "Error: You must provide at least one piece of text"
    usage
  end
end

#imagesObject



1
2
3
# File 'lib/meme_generator/cli.rb', line 1

def images
  MemeGenerator.meme_paths.values
end

#install_autocompleteObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/meme_generator/cli.rb', line 51

def install_autocomplete
  path = File.join(File.dirname(__FILE__), "..", "..", "script", "autocomplete.sh")
  puts <<-END
Source autocomplete.sh in your ~/.bashrc:

    $ echo "source #{path}" >> ~/.bashrc

Then source the profile:

    $ source ~/.bashrc
    
Or if you're using a mac

    $ echo "source #{path}" >> ~/.bash_profile
    
and
    $ source ~/.bash_profile

You can copy the path to autocomplete.sh somewhere in your home directory if
you upgrade gem versions, but it should always work.

(Sorry, this sucks but I don't know a foolproof way to do this)
END
  exit 0
end

#list_generatorsObject



10
11
12
13
14
15
16
17
# File 'lib/meme_generator/cli.rb', line 10

def list_generators
  names = images.map { |path|
    File.basename(path).gsub(/\..*/, '')
  }.sort

  names.each { |name| puts name }
  exit 0
end

#parse_path(string) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/meme_generator/cli.rb', line 19

def parse_path(string)
  if string =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
    path = "/tmp/memegen-download-#{Time.now.to_i}"
    `curl "#{string}" -o #{path} --silent`
  elsif path = images.find { |p| p =~ /\/#{string}\..*$/ }
  else
    puts "Error: Image not found. Use --list to view installed images."
    exit 1
  end
  path
end

#usageObject



5
6
7
8
# File 'lib/meme_generator/cli.rb', line 5

def usage
  puts 'usage: memegen <image> <top> <bottom> [--list|-l] [--campfire|-c] [--groupme|-g] [--help|-h] [--install-autocomplete]'
  exit 1
end