dogsay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 419de087dc0d06698b2b7f5aedc248d9b085ec21
4
+ data.tar.gz: 002d450653aeafd65a13e92165c35bc9cf58dc8d
5
+ SHA512:
6
+ metadata.gz: d4b0a3d799628b9dfb8d59594fab90b0a0f1224e0d8fb04c3e86f488db41af7f4c57168df8accfa36fe549f74d56927e704df46cfe2c1c53fb7bbc56979454ee
7
+ data.tar.gz: d78a177e75d4ff3001d23a98b13ce954202225a5dcff8eb8c48920bf30ee8a9d367c31a81c00eebb4111e3b14f5f4a5e35ca81b8e46d819ba753cb3d5c0d46b3
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dogsay.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Forrest Fleming
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Dogsay
2
+
3
+ It's like cowsay, but with a dog.
4
+
5
+ ## Installation
6
+ ```
7
+ % gem install dogsay
8
+ ```
9
+
10
+ ## Usage
11
+ ```
12
+ % dogsay Woof
13
+ _ +--------------------------------------+
14
+ ,:'/ _..._ | Woof |
15
+ // ( `""-.._.' +--------------------------------------+
16
+ \| / 6\___ /
17
+ | 6 4
18
+ | /
19
+ \_ .--'
20
+ (_'---'`)
21
+ / `'---`()
22
+ ,' |
23
+ , .'` |
24
+ )\ _.-' ;
25
+ / | .'` _ /
26
+ /` / .' '. , |
27
+ / / / \ ; | |
28
+ | \ | | .| | |
29
+ \ `"| /.-' | | |
30
+ '-..-\ _.;.._ | |.;-.
31
+ \ <`.._ )) | .;-. ))
32
+ (__. ` ))-' \_ ))'
33
+ `'--"` `"""`
34
+ ```
35
+ or
36
+ ```
37
+ % fortune | dogsay
38
+ _ +--------------------------------------+
39
+ ,:'/ _..._ | Till then we shall be content to |
40
+ // ( `""-.._.' | admit openly, what you |
41
+ \| / 6\___ /| (religionists) whisper under your |
42
+ | 6 4 | breath or hide in technical jargon, |
43
+ | / | that the ancient secret is a secret |
44
+ \_ .--' | still; that man knows nothing of the |
45
+ (_'---'`) | Infinite and Absolute; and that, |
46
+ / `'---`() | knowing nothing, he had better not |
47
+ ,' | | be dogmatic about his ignorance. |
48
+ , .'` | | And, meanwhile, we will endeavour to |
49
+ )\ _.-' ; | be as charitable as possible, and |
50
+ / | .'` _ / | whilst you trumpet forth officially |
51
+ /` / .' '. , | | your contempt for our skepticism, we |
52
+ / / / \ ; | | | will at least try to believe that |
53
+ | \ | | .| | | | you are imposed upon by your own |
54
+ \ `"| /.-' | | | | bluster. - Leslie Stephen, "An |
55
+ '-..-\ _.;.._ | |.;-. | agnostic's Apology", Fortnightly |
56
+ \ <`.._ )) | .;-. )) | Review, 1876 |
57
+ (__. ` ))-' \_ ))' +--------------------------------------+
58
+ `'--"` `"""`
59
+
60
+ ```
61
+ ## Contributing
62
+
63
+ 1. Fork it ( https://github.com/ffleming/dogsay/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create a new Pull Request
68
+
69
+ ## Todo
70
+ * Tests
71
+ * More dogs!
72
+
73
+ ##Acknowledgments
74
+ * `sit.dog` by 'dgs' at [Ascii-art.de](http://www.ascii-art.de/ascii/def/dogs.txt)
75
+ * `terrier.dog` from [Ascii-art.de](http://www.ascii-art.de/ascii/def/dogs.txt)
76
+ * `small_sit.dog` from [AsciiWorld.com](http://www.asciiworld.com/-Dogs-.html)
77
+ * `running.dog` from [AsciiWorld.com](http://www.asciiworld.com/-Dogs-.html)
78
+ * `gsd.dog` from 'hrr' at [chris.com](http://www.chris.com/ascii/index.php?art=animals/dogs)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/dogsay ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dogsay'
3
+ require 'optparse'
4
+
5
+ def opts_from_cli
6
+ options = {}
7
+ opt_parser = OptionParser.new do |opts|
8
+ opts.program_name = 'dogsay'
9
+ opts.banner = "#{opts.program_name} [options]"
10
+ opts.on('-d DOG', '--dog DOG', 'Display a particular dog') { |dog| options[:dog] = dog.to_sym }
11
+ opts.on('-s', '--strip', 'Strip newlines from input') { options[:strip] = true }
12
+ opts.on('-l', '--list', 'List available dogs') { options[:all_dogs] = true }
13
+ opts.on('-h', '--help', 'Display this screen') { puts opts ; exit(true) }
14
+ end
15
+ begin
16
+ opt_parser.parse!
17
+ rescue OptionParser::InvalidOption => e
18
+ puts e.message
19
+ puts opts
20
+ exit false
21
+ end
22
+ options
23
+ end
24
+
25
+ options = opts_from_cli
26
+ if options[:all_dogs]
27
+ puts "Possible dogs are: #{Dogsay::Dog.all}"
28
+ exit true
29
+ end
30
+ input = ARGV.empty? ? ARGF.read : ARGV.join(' ')
31
+ puts Dogsay.say(input, options)
data/dogsay.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dogsay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dogsay"
8
+ spec.version = Dogsay::VERSION
9
+ spec.authors = ["Forrest Fleming"]
10
+ spec.email = ["ffleming@gmail.com"]
11
+ spec.summary = %q{Like cowsay, but with a dog}
12
+ spec.description = %q{Prints CLI arguments or STDIN in speech bubble, said by a dog. Dogs are better than cows, after all.}
13
+ spec.homepage = 'http://github.com/ffleming/dogsay'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ end
@@ -0,0 +1,19 @@
1
+ module CoreExtensions
2
+ module Array
3
+ module Padding
4
+ def pad_to!(elements, opts={})
5
+ pad_obj = opts.fetch(:with, nil)
6
+ if self.length < elements
7
+ (elements - self.length).times { self << pad_obj }
8
+ self
9
+ end
10
+ end
11
+
12
+ def pad_to(elements, opts={})
13
+ ret = self.dup
14
+ ret.pad_to!(elements, opts)
15
+ ret
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module CoreExtensions
2
+ module String
3
+ module Box
4
+ def space_at(width, opts={})
5
+ separator = opts.fetch(:on, / /)
6
+ self.split(separator).map do |word|
7
+ word.scan(/.{1,#{width}}/m)
8
+ end.flatten.join(' ')
9
+ end
10
+
11
+ def wrap(width)
12
+ self.split("\n").map! do |line|
13
+ line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
14
+ end.join("\n")
15
+ end
16
+
17
+ def boxed(width, opts={})
18
+ justify = opts.fetch(:justify, :center)
19
+ raise ArgumentError.new, "Width must be >= 5" unless width >= 5
20
+ raise ArgumentError.new, ":justify must be :ljust, :rjust, or :center" unless %i(ljust rjust center).include? justify
21
+ arr = self.split("\n").map do |l|
22
+ "| #{l.send(justify, width - 4)} |"
23
+ end
24
+ header_line = "+#{'-' * (width - 2)}+"
25
+ [header_line, *arr, header_line].join("\n")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ module Dogsay::AsciiArt
2
+ attr_reader :ascii
3
+ def add_art(art, opts={})
4
+ case opts.fetch(:on_the, :right)
5
+ when :right then join_h ascii, art
6
+ when :left then join_h art, ascii
7
+ when :bottom then join_v ascii, art
8
+ when :top then join_v art, ascii
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def join_v(str1, str2)
15
+ (str1.split("\n") + str2.split("\n")).join("\n")
16
+ end
17
+
18
+ def join_h(l_str, r_str)
19
+ l_arr, r_arr = l_str.split("\n"), r_str.split("\n")
20
+ l_arr, r_arr = normalized_arrays_from(l_str, r_str)
21
+ (0..l_arr.length - 1).map do |i|
22
+ "#{l_arr[i]}#{r_arr[i]}"
23
+ end.join("\n")
24
+ end
25
+
26
+ def normalized_arrays_from(l_str, r_str)
27
+ l_arr, r_arr = l_str.split("\n"), r_str.split("\n")
28
+ max_arr_length = [l_arr.length, r_arr.length].max
29
+ [l_arr, r_arr].map do |array|
30
+ max_str_length = array.map(&:length).max
31
+ array.pad_to(max_arr_length, with: ' ' * max_str_length)
32
+ end
33
+ end
34
+ end
data/lib/dogsay/dog.rb ADDED
@@ -0,0 +1,34 @@
1
+ class Dogsay::Dog
2
+ include Dogsay::AsciiArt
3
+ attr_reader :text_position
4
+ def initialize(opts={})
5
+ raise ArgumentError.new, 'Must provide :dog' unless opts.has_key? :dog
6
+ filename = File.join( File.dirname(__FILE__), 'dogs', "#{opts[:dog]}.dog")
7
+ begin
8
+ hsh = YAML.load_file filename
9
+ @ascii = ascii_from(hsh)
10
+ @text_position = hsh[:text_position]
11
+ rescue Errno::ENOENT
12
+ abort "Dog '#{opts[:dog]}' not found"
13
+ end
14
+ end
15
+
16
+ def to_s
17
+ @ascii
18
+ end
19
+
20
+ def self.all
21
+ find_str = File.join( File.dirname(__FILE__), 'dogs', "*.dog")
22
+ Dir[find_str].map do |f|
23
+ File.basename(f, File.extname(f))
24
+ end.join ' '
25
+ end
26
+
27
+ private
28
+
29
+ def ascii_from(hash)
30
+ dog_lines = hash[:dog].split("\n")
31
+ max_length = dog_lines.map(&:length).max
32
+ dog_lines.map { |l| l.ljust(max_length) }.join("\n")
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ ---
2
+ :text_position: :right
3
+ :dog: |2
4
+ ;\
5
+ |' \
6
+ _ ; : ;
7
+ / `-. /: : |
8
+ | ,-.`-. ,': : |
9
+ \ : `. `. ,'-. : |
10
+ \ ; ; `-.__,' `-.| /
11
+ \ ; ; ::: ,::'`:. `. /
12
+ \ `-. : ` :. `. \ /
13
+ \ \ , ; ,: (\
14
+ \ :., :. ,'o)): ` `-.
15
+ ,/,' ;' ,::"'`.`---' `. `-._
16
+ ,/ : ; '" `;' ,--`.
17
+ ;/ :; ; ,:' ( ,:)
18
+ ,.,:. ; ,:., ,-._ `. \""'/
19
+ '::' `:'` ,'( \`._____.-'"'
20
+ ;, ; `. `. `._`-. \\
21
+ ;:. ;: `-._`-.\ \`.
22
+ '`:. : |' `. `\ ) \
23
+ ` ;: | `--\__,'
24
+ '` ,'
25
+ ,-'
@@ -0,0 +1,9 @@
1
+ ---
2
+ :text_position: :top
3
+ :dog: |2
4
+ \
5
+ .--~~,__
6
+ :-....,-------`~~'._.'
7
+ `-,,, ,_ ;'~U'
8
+ _,-' ,'`-__; '--.
9
+ (_/'~~ ''''(;
@@ -0,0 +1,24 @@
1
+ ---
2
+ :text_position: :right
3
+ :dog: |2
4
+ _
5
+ ,:'/ _..._
6
+ // ( `""-.._.'
7
+ \| / 6\___ /
8
+ | 6 4
9
+ | /
10
+ \_ .--'
11
+ (_'---'`)
12
+ / `'---`()
13
+ ,' |
14
+ , .'` |
15
+ )\ _.-' ;
16
+ / | .'` _ /
17
+ /` / .' '. , |
18
+ / / / \ ; | |
19
+ | \ | | .| | |
20
+ \ `"| /.-' | | |
21
+ '-..-\ _.;.._ | |.;-.
22
+ \ <`.._ )) | .;-. ))
23
+ (__. ` ))-' \_ ))'
24
+ `'--"` `"""`
@@ -0,0 +1,13 @@
1
+ ---
2
+ :text_position: :top
3
+ :dog: |2
4
+ \ _
5
+ \ / \
6
+ /|oo \
7
+ (_| /_)
8
+ `@/ \
9
+ | \ _
10
+ \|| \ //
11
+ |||\ / \//
12
+ _//|| _\ /
13
+ (_/(_|(____/
@@ -0,0 +1,9 @@
1
+ ---
2
+ :text_position: :top
3
+ :dog: |2
4
+ \
5
+ __
6
+ \ ______/ V`-,
7
+ } /~~
8
+ /_)^ --,r'
9
+ |b |b
@@ -0,0 +1,10 @@
1
+ class Dogsay::TextBox
2
+ include Dogsay::AsciiArt
3
+ attr_reader :text_width, :separator, :raw
4
+ def initialize(text, opts={})
5
+ @text_width = opts.fetch(:text_width, 40)
6
+ @separator = opts.fetch(:strip, false) ? ' ' : / /
7
+ @raw = text
8
+ @ascii = text.space_at(text_width - 4, on: separator).wrap(text_width - 4).boxed(text_width)
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Dogsay
2
+ VERSION = '0.1.0'
3
+ end
data/lib/dogsay.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'core_extensions/array/padding'
2
+ require 'core_extensions/string/box'
3
+ require 'dogsay/version'
4
+ require 'dogsay/ascii_art'
5
+ require 'dogsay/dog'
6
+ require 'dogsay/text_box'
7
+ require 'yaml'
8
+ Array.include CoreExtensions::Array::Padding
9
+ String.include CoreExtensions::String::Box
10
+
11
+ module Dogsay
12
+ class << self
13
+ def say(string, opts={})
14
+ dog = Dogsay::Dog.new(config.merge opts)
15
+ text = Dogsay::TextBox.new(string, opts)
16
+ dog.add_art(text.ascii, on_the: dog.text_position)
17
+ end
18
+
19
+ private
20
+
21
+ def config
22
+ begin
23
+ defaults.merge(YAML.load_file "#{ENV['HOME']}/.dogsay")
24
+ rescue Errno::ENOENT
25
+ defaults
26
+ end
27
+ end
28
+
29
+ def defaults
30
+ { dog: :sit }
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dogsay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Forrest Fleming
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ description: Prints CLI arguments or STDIN in speech bubble, said by a dog. Dogs
28
+ are better than cows, after all.
29
+ email:
30
+ - ffleming@gmail.com
31
+ executables:
32
+ - dogsay
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/dogsay
42
+ - dogsay.gemspec
43
+ - lib/core_extensions/array/padding.rb
44
+ - lib/core_extensions/string/box.rb
45
+ - lib/dogsay.rb
46
+ - lib/dogsay/ascii_art.rb
47
+ - lib/dogsay/dog.rb
48
+ - lib/dogsay/dogs/gsd.dog
49
+ - lib/dogsay/dogs/running.dog
50
+ - lib/dogsay/dogs/sit.dog
51
+ - lib/dogsay/dogs/small_sit.dog
52
+ - lib/dogsay/dogs/terrier.dog
53
+ - lib/dogsay/text_box.rb
54
+ - lib/dogsay/version.rb
55
+ homepage: http://github.com/ffleming/dogsay
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.2.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Like cowsay, but with a dog
79
+ test_files: []