dogsay 0.1.1 → 0.2.0

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: f8138555528625bec820e82389b48cc1adbfd9ca
4
- data.tar.gz: 1f9f1088da85289cc319f0a1093790cc6cefb2d2
3
+ metadata.gz: b2b674f44a8f3afeaff1d01b173e97966ef5bb1b
4
+ data.tar.gz: 7bb42492927b32a2a0823f6eea93aa200b34f01a
5
5
  SHA512:
6
- metadata.gz: 122e972476cd460b53871abd1338d9e516ea45c5d4f85cdc8fb14c49ee6f2118c717c2db6f6dd6a5fec72c19600399e7c78ddb65c944054e827aa207eb474059
7
- data.tar.gz: 511aa0084147c1fbef4d05b90ac90b11e2365f8baadc4a85bf48caf0041700ae81557f0a259d3cfa6e86c7d49ce0523cf6283227c89a38a403793d2c425d80cd
6
+ metadata.gz: 80adee9811f34d448085e9d36eca663c6100b19a7c6390fd416a8978339ffc86f4753e7b04d196cb598eb42fbfb5390fcb9a07dd4441523e04b3025695328b96
7
+ data.tar.gz: 29c2ffca21bb52ce5ff17893f60ef259897e2313f5f9d517e22dadcf03f189ed0c0d4f74cda767107bb56d94cfd4251d0e431a57b43a2b0be143fd2cd2f85da7
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Dogsay
2
+ [![Gem Version](https://badge.fury.io/rb/dogsay.svg)](http://badge.fury.io/rb/dogsay)
3
+ [![Code Climate](https://codeclimate.com/github/ffleming/dogsay/badges/gpa.svg)](https://codeclimate.com/github/ffleming/dogsay)
2
4
 
3
5
  It's like cowsay, but with a dog.
4
6
 
@@ -56,8 +58,10 @@ or
56
58
  \ <`.._ )) | .;-. )) | Review, 1876 |
57
59
  (__. ` ))-' \_ ))' +--------------------------------------+
58
60
  `'--"` `"""`
59
-
60
61
  ```
62
+
63
+ If you're feeling saucy, you can try out `dinosay` as well.
64
+
61
65
  ## Contributing
62
66
 
63
67
  1. Fork it ( https://github.com/ffleming/dogsay/fork )
@@ -67,12 +71,14 @@ or
67
71
  5. Create a new Pull Request
68
72
 
69
73
  ## Todo
70
- * Tests
71
74
  * More dogs!
75
+ * Extract chains after `do...end` to their own methods
72
76
 
73
77
  ##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)
78
+ * `default.dog` by 'dgs' at [Ascii-art.de](http://www.ascii-art.de/ascii/def/dogs.txt)
79
+ * `small.dog` from [Ascii-art.de](http://www.ascii-art.de/ascii/def/dogs.txt)
80
+ * `sit.dog` from [AsciiWorld.com](http://www.asciiworld.com/-Dogs-.html)
77
81
  * `running.dog` from [AsciiWorld.com](http://www.asciiworld.com/-Dogs-.html)
78
82
  * `gsd.dog` by 'hrr' at [chris.com](http://www.chris.com/ascii/index.php?art=animals/dogs)
83
+ * `default.dino` by `CJ` at [retrojunkie.com](http://www.retrojunkie.com/asciiart/animals/dinos.htm)
84
+ * `small.dino` by `PapaJ` at [retrojunkie.com](http://www.retrojunkie.com/asciiart/animals/dinos.htm)
data/bin/dinosay ADDED
@@ -0,0 +1,53 @@
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 = File.basename(__FILE__)
9
+ opts.banner = "#{opts.program_name} [options]"
10
+ opts.on('-d DOG', '--dog DOG', 'Display a particular dog') { |pose| options[:pose] = pose.to_sym }
11
+ opts.on('-a ANIMAL', '--animal ANIMAL', 'Display a non-dog animal') { |animal| options[:animal] = animal.to_sym }
12
+ opts.on('-w WIDTH', '--width WIDTH', 'Width for text box') { |width| options[:text_width] = width.to_i }
13
+ opts.on('-j JUSTIFY', '--justify JUSTIFY', 'Justify text', 'Options are ljust, rjust, and center') { |j| options[:justify] = j.to_sym }
14
+ opts.on('-r', '--raw', 'Don\'t process text') { options[:raw] = true }
15
+ opts.on('-s', '--strip', 'Strip newlines from input') { options[:strip] = true }
16
+ opts.on('-l', '--list', 'List available dogs') { options[:all_dogs] = true }
17
+ opts.on('--list-animals', 'List available animal types') { options[:all_animals] = true }
18
+ opts.on('-h', '--help', 'Display this screen') { options[:help] = true ; options[:input] = opts.to_s }
19
+ end
20
+ begin
21
+ opt_parser.parse!
22
+ rescue OptionParser::InvalidOption => e
23
+ puts e.message
24
+ exit false
25
+ end
26
+ options[:animal] = File.basename($0).sub(/say$/,'').to_sym if options[:animal].nil?
27
+ options
28
+ end
29
+
30
+ options = opts_from_cli
31
+
32
+ if options[:help]
33
+ options.merge!({justify: :ljust, text_width: 55, raw: true})
34
+ puts Dogsay.say(options[:input], options)
35
+ exit(true)
36
+ end
37
+ if options[:all_dogs]
38
+ animal = options.fetch(:animal, :dog)
39
+ puts "Possible #{animal}s are: #{Dogsay::Dog.all(animal)}"
40
+ exit true
41
+ end
42
+ if options[:all_animals]
43
+ puts "Possible animals are: #{Dogsay::Dog.all_animals}"
44
+ exit true
45
+ end
46
+
47
+ input = ARGV.empty? ? ARGF.read : ARGV.join(' ')
48
+ begin
49
+ puts Dogsay.say(input, options)
50
+ rescue Dogsay::InvalidDogError => e
51
+ puts e.message
52
+ exit false
53
+ end
data/bin/dogsay CHANGED
@@ -5,12 +5,17 @@ require 'optparse'
5
5
  def opts_from_cli
6
6
  options = {}
7
7
  opt_parser = OptionParser.new do |opts|
8
- opts.program_name = 'dogsay'
8
+ opts.program_name = File.basename(__FILE__)
9
9
  opts.banner = "#{opts.program_name} [options]"
10
- opts.on('-d DOG', '--dog DOG', 'Display a particular dog') { |dog| options[:dog] = dog.to_sym }
10
+ opts.on('-d DOG', '--dog DOG', 'Display a particular dog') { |pose| options[:pose] = pose.to_sym }
11
+ opts.on('-a ANIMAL', '--animal ANIMAL', 'Display a non-dog animal') { |animal| options[:animal] = animal.to_sym }
12
+ opts.on('-w WIDTH', '--width WIDTH', 'Width for text box') { |width| options[:text_width] = width.to_i }
13
+ opts.on('-j JUSTIFY', '--justify JUSTIFY', 'Justify text', 'Options are ljust, rjust, and center') { |j| options[:justify] = j.to_sym }
14
+ opts.on('-r', '--raw', 'Don\'t process text') { options[:raw] = true }
11
15
  opts.on('-s', '--strip', 'Strip newlines from input') { options[:strip] = true }
12
16
  opts.on('-l', '--list', 'List available dogs') { options[:all_dogs] = true }
13
- opts.on('-h', '--help', 'Display this screen') { puts opts ; exit(true) }
17
+ opts.on('--list-animals', 'List available animal types') { options[:all_animals] = true }
18
+ opts.on('-h', '--help', 'Display this screen') { options[:help] = true ; options[:input] = opts.to_s }
14
19
  end
15
20
  begin
16
21
  opt_parser.parse!
@@ -18,13 +23,31 @@ def opts_from_cli
18
23
  puts e.message
19
24
  exit false
20
25
  end
26
+ options[:animal] = File.basename($0).sub(/say$/,'').to_sym if options[:animal].nil?
21
27
  options
22
28
  end
23
29
 
24
30
  options = opts_from_cli
31
+
32
+ if options[:help]
33
+ options.merge!({justify: :ljust, text_width: 55, raw: true})
34
+ puts Dogsay.say(options[:input], options)
35
+ exit(true)
36
+ end
25
37
  if options[:all_dogs]
26
- puts "Possible dogs are: #{Dogsay::Dog.all}"
38
+ animal = options.fetch(:animal, :dog)
39
+ puts "Possible #{animal}s are: #{Dogsay::Dog.all(animal)}"
40
+ exit true
41
+ end
42
+ if options[:all_animals]
43
+ puts "Possible animals are: #{Dogsay::Dog.all_animals}"
27
44
  exit true
28
45
  end
46
+
29
47
  input = ARGV.empty? ? ARGF.read : ARGV.join(' ')
30
- puts Dogsay.say(input, options)
48
+ begin
49
+ puts Dogsay.say(input, options)
50
+ rescue Dogsay::InvalidDogError => e
51
+ puts e.message
52
+ exit false
53
+ end
data/dogsay.gemspec CHANGED
@@ -9,14 +9,16 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Forrest Fleming"]
10
10
  spec.email = ["ffleming@gmail.com"]
11
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.}
12
+ spec.description = %q{Prints CLI arguments or STDIN in a speech bubble, said by a dog. Dogs are better than cows, after all.}
13
13
  spec.homepage = 'http://github.com/ffleming/dogsay'
14
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
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.test_files = spec.files.grep(%r{^(spec)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rspec', '~> 3'
23
+ spec.add_development_dependency 'simplecov', '~> 0'
22
24
  end
@@ -10,11 +10,11 @@ module CoreExtensions
10
10
 
11
11
  def wrap(width)
12
12
  self.split("\n").map! do |line|
13
- line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
13
+ line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line.strip
14
14
  end.join("\n")
15
15
  end
16
16
 
17
- def boxed(width, opts={})
17
+ def boxed(width=40, opts={})
18
18
  justify = opts.fetch(:justify, :center)
19
19
  raise ArgumentError.new, "Width must be >= 5" unless width >= 5
20
20
  raise ArgumentError.new, ":justify must be :ljust, :rjust, or :center" unless %i(ljust rjust center).include? justify
data/lib/dogsay/dog.rb CHANGED
@@ -1,31 +1,46 @@
1
1
  class Dogsay::Dog
2
2
  include Dogsay::AsciiArt
3
- attr_reader :text_position
3
+ attr_reader :text_position, :animal, :pose
4
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
5
+ @animal = opts.fetch :animal
6
+ @pose = opts.fetch :pose
7
+ load_yaml
14
8
  end
15
9
 
16
10
  def to_s
17
11
  @ascii
18
12
  end
19
13
 
20
- def self.all
21
- find_str = File.join( File.dirname(__FILE__), 'dogs', "*.dog")
14
+ def self.all(animal=:dog)
15
+ find_str = File.join( File.dirname(__FILE__), 'dogs', "*.#{animal}")
22
16
  Dir[find_str].map do |f|
23
17
  File.basename(f, File.extname(f))
24
- end.join ' '
18
+ end.join ', '
19
+ end
20
+
21
+ def self.all_animals
22
+ find_str = File.join( File.dirname(__FILE__), 'dogs', '*')
23
+ Dir[find_str].map do |f|
24
+ File.extname(f)[1..-1]
25
+ end.uniq.join ', '
25
26
  end
26
27
 
27
28
  private
28
29
 
30
+ def filename
31
+ File.join( File.dirname(__FILE__), 'dogs', "#{pose}.#{animal}")
32
+ end
33
+
34
+ def load_yaml
35
+ begin
36
+ yaml_hash = YAML.load_file filename
37
+ rescue Errno::ENOENT
38
+ raise Dogsay::InvalidDogError.new("Invalid dog file #{filename}")
39
+ end
40
+ @ascii = ascii_from(yaml_hash)
41
+ @text_position = yaml_hash[:text_position]
42
+ end
43
+
29
44
  def ascii_from(hash)
30
45
  dog_lines = hash[:dog].split("\n")
31
46
  max_length = dog_lines.map(&:length).max
@@ -0,0 +1,33 @@
1
+ ---
2
+ :text_position: :left
3
+ :dog: |2
4
+
5
+ .-=-==--==--.
6
+ ..-==" ,'o`) `.
7
+ ,' `"' \
8
+ \ : ( `.__...._
9
+ | ) / `-=-.
10
+ : ,vv.-._ / / `---==-._
11
+ \/\/\/VV ^ d88`;' / `.
12
+ `` ^/d88P!' / , `._
13
+ ^/ !' ,. , / "-,,__,,--'""""-.
14
+ ^/ !' ,' \ . .( ( _ ) ) ) ) ))_,-.\
15
+ ^(__ ,!',"' ;:+.:%:a. \:.. . ,' ) ) ) ) ,"' '
16
+ ',,,'',' /o:::":%:%a. \:.:.: . ) ) _,'
17
+ """' ;':::'' `+%%%a._ \%:%| ;.). _,-""
18
+ ,-='_.-' ``:%::) )%:| /:._,"
19
+ (/(/" ," ,'_,'%%%: (_,'
20
+ ( (//(`.___; \
21
+ \ \ ` `
22
+ `. `. `. :
23
+ \. . .\ : . . . :
24
+ \. . .: `.. . .:
25
+ `..:.:\ \:...\
26
+ ;:.:.; ::...:
27
+ ):%:: :::::;
28
+ __,::%:( :::::
29
+ ,;:%%%%%%%: ;:%::
30
+ ;,--""-.`\ ,=--':%:%:\
31
+ /" "| /-".:%%%%%%%\
32
+ ;,-"'`)%%)
33
+ /" "|
@@ -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
+ `'--"` `"""`
@@ -1,24 +1,13 @@
1
1
  ---
2
- :text_position: :right
2
+ :text_position: :top
3
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
- `'--"` `"""`
4
+ \ _
5
+ \ / \
6
+ /|oo \
7
+ (_| /_)
8
+ `@/ \
9
+ | \ _
10
+ \|| \ //
11
+ |||\ / \//
12
+ _//|| _\ /
13
+ (_/(_|(____/
@@ -0,0 +1,9 @@
1
+ ---
2
+ :text_position: :right
3
+ :dog: |2
4
+ __
5
+ / _) /
6
+ _.----._/ /
7
+ / /
8
+ .--__/ ( | ( |'
9
+ '-__..-'|_|--|_|
File without changes
@@ -0,0 +1,2 @@
1
+ class Dogsay::InvalidDogError < StandardError
2
+ end
@@ -1,10 +1,12 @@
1
1
  class Dogsay::TextBox
2
2
  include Dogsay::AsciiArt
3
- attr_reader :text_width, :separator, :raw
3
+ attr_reader :text_width, :separator, :justify, :raw
4
4
  def initialize(text, opts={})
5
5
  @text_width = opts.fetch(:text_width, 40)
6
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)
7
+ @justify = opts.fetch(:justify, :center)
8
+ max_width = text.split("\n").map(&:length).max
9
+ @raw = text.boxed(max_width + 4, justify: :ljust)
10
+ @ascii = text.space_at(text_width - 4, on: separator).wrap(text_width - 4).boxed(text_width, justify: justify)
9
11
  end
10
12
  end
@@ -1,3 +1,3 @@
1
1
  module Dogsay
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/dogsay.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'core_extensions/array/padding'
2
2
  require 'core_extensions/string/box'
3
+ require 'dogsay/errors'
3
4
  require 'dogsay/version'
4
5
  require 'dogsay/ascii_art'
5
6
  require 'dogsay/dog'
@@ -13,7 +14,8 @@ module Dogsay
13
14
  def say(string, opts={})
14
15
  dog = Dogsay::Dog.new(config.merge opts)
15
16
  text = Dogsay::TextBox.new(string, opts)
16
- dog.add_art(text.ascii, on_the: dog.text_position)
17
+ boxed = opts[:raw] ? text.raw : text.ascii
18
+ dog.add_art(boxed, on_the: dog.text_position)
17
19
  end
18
20
 
19
21
  private
@@ -27,7 +29,10 @@ module Dogsay
27
29
  end
28
30
 
29
31
  def defaults
30
- { dog: :sit }
32
+ {
33
+ animal: :dog,
34
+ pose: :default
35
+ }
31
36
  end
32
37
  end
33
38
  end
@@ -0,0 +1,37 @@
1
+ RSpec.describe Array do
2
+ let(:arr) { ['a', 'dog', 'barks'] }
3
+ describe '#pad_to' do
4
+ context 'no object specified' do
5
+ it 'should default to nil' do
6
+ expect(arr.pad_to(5)).to eq ['a', 'dog', 'barks', nil, nil]
7
+ expect(arr).to eq ['a', 'dog', 'barks']
8
+ end
9
+ end
10
+
11
+ context 'an object specified' do
12
+ it 'should pad with that object' do
13
+ expect(arr.pad_to(5, with: 'woof')).to eq ['a', 'dog', 'barks', 'woof', 'woof']
14
+ expect(arr).to eq ['a', 'dog', 'barks']
15
+ end
16
+ end
17
+ end
18
+
19
+ describe '#pad_to!' do
20
+ context 'no object specified' do
21
+ it 'should default to nil' do
22
+ array = arr.dup
23
+ array.pad_to!(5)
24
+ expect(array).to eq ['a', 'dog', 'barks', nil, nil]
25
+ end
26
+ end
27
+
28
+ context 'an object specified' do
29
+ it 'should pad with that object' do
30
+ array = arr.dup
31
+ array.pad_to!(5, with: 'woof')
32
+ expect(array).to eq ['a', 'dog', 'barks', 'woof', 'woof']
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,92 @@
1
+ RSpec.describe String do
2
+ let(:string) { 'Woof arf bark ruff rowf won' }
3
+ let(:long_string) { 'Arrrrooooooo' }
4
+ let(:linebreaks) { "Woof.\n Arf?\n Arroooooo!" }
5
+ describe '#space_at' do
6
+ context 'with / / as separator' do
7
+ context 'with short strings' do
8
+ it 'should not modify the string' do
9
+ expect(string.space_at 5, on: / /).to eq string
10
+ end
11
+ end
12
+ context 'with a long string' do
13
+ it 'should insert spaces appropriately' do
14
+ expect(long_string.space_at(5, on: / /)).to eq 'Arrrr ooooo oo'
15
+ end
16
+ end
17
+ context 'with a string with linebreaks' do
18
+ it 'should insert spaces appropriately' do
19
+ expect(linebreaks.space_at(5, on: / /)).to eq "Woof. \n Arf?\n Arroo oooo!"
20
+ end
21
+ end
22
+ end # / / as separator
23
+
24
+ context 'with \' \' as a separator' do
25
+ context 'with short strings' do
26
+ it 'should not modify the string' do
27
+ expect(string.space_at 5, on: / /).to eq string
28
+ end
29
+ end
30
+ context 'with a long string' do
31
+ it 'should insert spaces appropriately' do
32
+ expect(long_string.space_at(5, on: / /)).to eq 'Arrrr ooooo oo'
33
+ end
34
+ end
35
+ context 'with a string with linebreaks' do
36
+ it 'should insert spaces appropriately' do
37
+ expect(linebreaks.space_at(5, on: / /)).to eq "Woof. \n Arf?\n Arroo oooo!"
38
+ end
39
+ end
40
+ end # ' ' as separator
41
+ end # space_at
42
+
43
+ describe '#wrap' do
44
+ context 'with short strings' do
45
+ it 'should wrap appropriately' do
46
+ expect(string.wrap 5).to eq "Woof\narf\nbark\nruff\nrowf\nwon"
47
+ end
48
+ end
49
+ context 'with a long string' do
50
+ it 'should wrap appropriately' do
51
+ expect(long_string.wrap 5).to eq 'Arrrrooooooo'
52
+ end
53
+ end
54
+ context 'with a string with linebreaks' do
55
+ it 'should remove the spaces' do
56
+ expect(linebreaks.wrap 5).to eq "Woof.\nArf?\nArroooooo!"
57
+ end
58
+ end
59
+ end # wrap
60
+
61
+ describe '#boxed' do
62
+ context 'with a string of appropriate length' do
63
+ it 'should default to width 40' do
64
+ result = "+--------------------------------------+\n" <<
65
+ "| Woof arf bark ruff rowf won |\n" <<
66
+ "+--------------------------------------+"
67
+ expect(string.boxed).to eq result
68
+ end
69
+ context 'and width 20' do
70
+ it 'should box appropriately' do
71
+ result = "+------------------+\n" <<
72
+ "| Woof. |\n" <<
73
+ "| Arf? |\n" <<
74
+ "| Arroooooo! |\n" <<
75
+ "+------------------+"
76
+ expect(linebreaks.boxed 20).to eq result
77
+ end
78
+ end
79
+ context 'and width 5' do
80
+ it 'should box appriately' do
81
+ expect('!'.boxed 5).to eq "+---+\n| ! |\n+---+"
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'with a string that is too short' do
87
+ it 'should raise an exception' do
88
+ expect{string.boxed 4}.to raise_error
89
+ end
90
+ end
91
+ end #boxed
92
+ end
data/spec/dog_spec.rb ADDED
@@ -0,0 +1,47 @@
1
+ RSpec.describe Dogsay::Dog do
2
+ before :all do
3
+ $stderr = File.open('/dev/null', 'w')
4
+ end
5
+
6
+ describe '#initialize' do
7
+ context 'using defaults' do
8
+ let(:bad_dog) { Dogsay::Dog.new }
9
+ it 'should abort with an unspecifed dog' do
10
+ expect{bad_dog.animal}.to raise_error(KeyError)
11
+ end
12
+ end
13
+
14
+ context 'dog of :default' do
15
+ let(:sitting_dog) { Dogsay::Dog.new(pose: :default, animal: :dog) }
16
+ it 'should set :dog to :default' do
17
+ expect(sitting_dog.pose).to eq :default
18
+ end
19
+
20
+ it 'should set :animal to :dog' do
21
+ expect(sitting_dog.animal).to eq :dog
22
+ end
23
+
24
+ it 'should set :ascii correctly' do
25
+ sitting = File.open(File.join 'spec', 'fixtures', 'sit_to_s').read
26
+ expect(sitting_dog.to_s).to eq sitting
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '::all' do
32
+ it 'should list all dogs' do
33
+ expect(Dogsay::Dog.all).to include 'gsd'
34
+ expect(Dogsay::Dog.all).to include 'running'
35
+ expect(Dogsay::Dog.all).to include 'sit'
36
+ expect(Dogsay::Dog.all).to include 'small'
37
+ expect(Dogsay::Dog.all).to include 'default'
38
+ end
39
+ end
40
+
41
+ describe '::all_animals' do
42
+ it 'should list all animals' do
43
+ expect(Dogsay::Dog.all_animals).to include 'dino'
44
+ expect(Dogsay::Dog.all_animals).to include 'dog'
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,68 @@
1
+ RSpec.describe Dogsay do
2
+ before :all do
3
+ $stderr = File.open('/dev/null', 'w')
4
+ end
5
+
6
+ describe '#say' do
7
+ it 'shoud bark' do
8
+ woof = File.open(File.join 'spec', 'fixtures', 'say_woof').read
9
+ expect(Dogsay.say('woof')).to eq woof
10
+ end
11
+
12
+ it 'should know poetry' do
13
+ sappho = File.open(File.join 'spec', 'fixtures', 'say_sappho').read
14
+ poem = "We know this much\nDeath is an evil;\nwe have the gods'\n" <<
15
+ "word for it; they too\nwould die if death\nwere a good thing"
16
+ expect(Dogsay.say(poem)).to eq sappho
17
+ end
18
+
19
+ context 'without a configuration file' do
20
+ it 'should not raise errors' do
21
+ allow(YAML).to receive(:load_file) do |arg|
22
+ raise Errno::ENOENT if arg == "#{ENV['HOME']}/.dogsay"
23
+ { dog: "\nDOG\n", text_position: :top }
24
+ end
25
+ expect {Dogsay.say 'woof'}.to_not raise_error
26
+ end
27
+ end
28
+
29
+ context 'when missing dogfiles' do
30
+ it 'should abort' do
31
+ allow(YAML).to receive(:load_file) { raise Errno::ENOENT }
32
+ expect {Dogsay.say 'woof'}.to raise_error
33
+ end
34
+ end
35
+
36
+ it 'should be able to position text on the top' do
37
+ allow(YAML).to receive(:load_file) do |arg|
38
+ raise Errno::ENOENT if arg == "#{ENV['HOME']}/.dogsay"
39
+ { dog: "\nDOG\n", text_position: :top }
40
+ end
41
+ expect(Dogsay.say 'Woof', raw: true).to eq "+------+\n| Woof |\n+------+\n \nDOG"
42
+ end
43
+
44
+ it 'should be able to position text on the bottom' do
45
+ allow(YAML).to receive(:load_file) do |arg|
46
+ raise Errno::ENOENT if arg == "#{ENV['HOME']}/.dogsay"
47
+ { dog: "\nDOG\n", text_position: :bottom }
48
+ end
49
+ expect(Dogsay.say 'Woof', raw: true).to eq " \nDOG\n+------+\n| Woof |\n+------+"
50
+ end
51
+
52
+ it 'should be able to position text on the left' do
53
+ allow(YAML).to receive(:load_file) do |arg|
54
+ raise Errno::ENOENT if arg == "#{ENV['HOME']}/.dogsay"
55
+ { dog: "\nDOG\n", text_position: :left }
56
+ end
57
+ expect(Dogsay.say 'Woof', raw: true).to eq "+------+ \n| Woof |DOG\n+------+ "
58
+ end
59
+
60
+ it 'should be able to position text on the right' do
61
+ allow(YAML).to receive(:load_file) do |arg|
62
+ raise Errno::ENOENT if arg == "#{ENV['HOME']}/.dogsay"
63
+ { dog: "\nDOG\n", text_position: :right }
64
+ end
65
+ expect(Dogsay.say 'Woof', raw: true).to eq " +------+\nDOG| Woof |\n +------+"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,21 @@
1
+ _ +--------------------------------------+
2
+ ,:'/ _..._ | We know this much |
3
+ // ( `""-.._.' | Death is an evil; |
4
+ \| / 6\___ /| we have the gods' |
5
+ | 6 4 | word for it; they too |
6
+ | / | would die if death |
7
+ \_ .--' | were a good thing |
8
+ (_'---'`) +--------------------------------------+
9
+ / `'---`()
10
+ ,' |
11
+ , .'` |
12
+ )\ _.-' ;
13
+ / | .'` _ /
14
+ /` / .' '. , |
15
+ / / / \ ; | |
16
+ | \ | | .| | |
17
+ \ `"| /.-' | | |
18
+ '-..-\ _.;.._ | |.;-.
19
+ \ <`.._ )) | .;-. ))
20
+ (__. ` ))-' \_ ))'
21
+ `'--"` `"""`
@@ -0,0 +1,21 @@
1
+ _ +--------------------------------------+
2
+ ,:'/ _..._ | woof |
3
+ // ( `""-.._.' +--------------------------------------+
4
+ \| / 6\___ /
5
+ | 6 4
6
+ | /
7
+ \_ .--'
8
+ (_'---'`)
9
+ / `'---`()
10
+ ,' |
11
+ , .'` |
12
+ )\ _.-' ;
13
+ / | .'` _ /
14
+ /` / .' '. , |
15
+ / / / \ ; | |
16
+ | \ | | .| | |
17
+ \ `"| /.-' | | |
18
+ '-..-\ _.;.._ | |.;-.
19
+ \ <`.._ )) | .;-. ))
20
+ (__. ` ))-' \_ ))'
21
+ `'--"` `"""`
@@ -0,0 +1,21 @@
1
+ _
2
+ ,:'/ _..._
3
+ // ( `""-.._.'
4
+ \| / 6\___ /
5
+ | 6 4
6
+ | /
7
+ \_ .--'
8
+ (_'---'`)
9
+ / `'---`()
10
+ ,' |
11
+ , .'` |
12
+ )\ _.-' ;
13
+ / | .'` _ /
14
+ /` / .' '. , |
15
+ / / / \ ; | |
16
+ | \ | | .| | |
17
+ \ `"| /.-' | | |
18
+ '-..-\ _.;.._ | |.;-.
19
+ \ <`.._ )) | .;-. ))
20
+ (__. ` ))-' \_ ))'
21
+ `'--"` `"""`
@@ -0,0 +1,47 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ require 'simplecov'
20
+ SimpleCov.start
21
+ require_relative '../lib/dogsay'
22
+ RSpec.configure do |config|
23
+ config.expect_with :rspec do |expectations|
24
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
25
+ end
26
+
27
+ config.mock_with :rspec do |mocks|
28
+ mocks.verify_partial_doubles = true
29
+ end
30
+
31
+ config.run_all_when_everything_filtered = true
32
+ config.disable_monkey_patching!
33
+
34
+ config.warnings = true
35
+
36
+ if config.files_to_run.one?
37
+ config.default_formatter = 'doc'
38
+ end
39
+
40
+ # Print the 10 slowest examples and example groups at the
41
+ # end of the spec run, to help surface which specs are running
42
+ # particularly slow.
43
+ # config.profile_examples = 5
44
+
45
+ config.order = :random
46
+ Kernel.srand config.seed
47
+ end
@@ -0,0 +1,50 @@
1
+ RSpec.describe Dogsay::TextBox do
2
+ before :all do
3
+ $stderr = File.open('/dev/null', 'w')
4
+ end
5
+
6
+ describe '#initialize' do
7
+ let(:default) { Dogsay::TextBox.new("Woof")}
8
+ let(:specified) { Dogsay::TextBox.new("Woof", text_width: 20, justify: :ljust, strip: true, )}
9
+ context 'using defaults' do
10
+ it 'should set :text_width to 40' do
11
+ expect(default.text_width).to eq 40
12
+ end
13
+ it 'should set :separator to / /' do
14
+ expect(default.separator).to eq(/ /)
15
+ end
16
+ it 'should set :justify to :center' do
17
+ expect(default.justify).to eq :center
18
+ end
19
+ it 'should set :raw to a minimal box' do
20
+ expect(default.raw).to eq "+------+\n| Woof |\n+------+"
21
+ end
22
+ it 'should set :ascii to a spaced box' do
23
+ expect(default.ascii).to eq "+--------------------------------------+\n" <<
24
+ "| Woof |\n" <<
25
+ "+--------------------------------------+"
26
+ end
27
+ end
28
+
29
+ context 'using specified values' do
30
+ it 'should set :text_width to 20' do
31
+ expect(specified.text_width).to eq 20
32
+ end
33
+ it 'should set :separator to \' \'' do
34
+ expect(specified.separator).to eq ' '
35
+ end
36
+ it 'should set :justify to :center' do
37
+ expect(specified.justify).to eq :ljust
38
+ end
39
+ it 'should set :raw to a minimal box' do
40
+ expect(specified.raw).to eq "+------+\n| Woof |\n+------+"
41
+ end
42
+ it 'should set :ascii to a spaced box' do
43
+ expect(specified.ascii).to eq "+------------------+\n" <<
44
+ "| Woof |\n" <<
45
+ "+------------------+"
46
+ end
47
+ end
48
+
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogsay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Forrest Fleming
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-04 00:00:00.000000000 Z
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,51 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
- description: Prints CLI arguments or STDIN in speech bubble, said by a dog. Dogs
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Prints CLI arguments or STDIN in a speech bubble, said by a dog. Dogs
28
56
  are better than cows, after all.
29
57
  email:
30
58
  - ffleming@gmail.com
31
59
  executables:
60
+ - dinosay
32
61
  - dogsay
33
62
  extensions: []
34
63
  extra_rdoc_files: []
35
64
  files:
36
65
  - ".gitignore"
66
+ - ".rspec"
37
67
  - Gemfile
38
68
  - LICENSE.txt
39
69
  - README.md
40
70
  - Rakefile
71
+ - bin/dinosay
41
72
  - bin/dogsay
42
73
  - dogsay.gemspec
43
74
  - lib/core_extensions/array/padding.rb
@@ -45,13 +76,25 @@ files:
45
76
  - lib/dogsay.rb
46
77
  - lib/dogsay/ascii_art.rb
47
78
  - lib/dogsay/dog.rb
79
+ - lib/dogsay/dogs/default.dino
80
+ - lib/dogsay/dogs/default.dog
48
81
  - lib/dogsay/dogs/gsd.dog
49
82
  - lib/dogsay/dogs/running.dog
50
83
  - lib/dogsay/dogs/sit.dog
51
- - lib/dogsay/dogs/small_sit.dog
52
- - lib/dogsay/dogs/terrier.dog
84
+ - lib/dogsay/dogs/small.dino
85
+ - lib/dogsay/dogs/small.dog
86
+ - lib/dogsay/errors.rb
53
87
  - lib/dogsay/text_box.rb
54
88
  - lib/dogsay/version.rb
89
+ - spec/core_extensions/array_spec.rb
90
+ - spec/core_extensions/string_spec.rb
91
+ - spec/dog_spec.rb
92
+ - spec/dogsay_spec.rb
93
+ - spec/fixtures/say_sappho
94
+ - spec/fixtures/say_woof
95
+ - spec/fixtures/sit_to_s
96
+ - spec/spec_helper.rb
97
+ - spec/text_box_spec.rb
55
98
  homepage: http://github.com/ffleming/dogsay
56
99
  licenses:
57
100
  - MIT
@@ -76,4 +119,13 @@ rubygems_version: 2.2.2
76
119
  signing_key:
77
120
  specification_version: 4
78
121
  summary: Like cowsay, but with a dog
79
- test_files: []
122
+ test_files:
123
+ - spec/core_extensions/array_spec.rb
124
+ - spec/core_extensions/string_spec.rb
125
+ - spec/dog_spec.rb
126
+ - spec/dogsay_spec.rb
127
+ - spec/fixtures/say_sappho
128
+ - spec/fixtures/say_woof
129
+ - spec/fixtures/sit_to_s
130
+ - spec/spec_helper.rb
131
+ - spec/text_box_spec.rb
@@ -1,13 +0,0 @@
1
- ---
2
- :text_position: :top
3
- :dog: |2
4
- \ _
5
- \ / \
6
- /|oo \
7
- (_| /_)
8
- `@/ \
9
- | \ _
10
- \|| \ //
11
- |||\ / \//
12
- _//|| _\ /
13
- (_/(_|(____/