dogeify 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGE1NDE5NzU4NGQxZjFlYjUyMGExNDRkOWFmNjIxN2YyMmNmYzcwNw==
5
- data.tar.gz: !binary |-
6
- MzlkZjM2ODk1M2E5Yjg3OGU2YjU2NDNiZmJhNTQxMDMwZWFkMDFiYw==
2
+ SHA1:
3
+ metadata.gz: 919803b45f9326a80f0031d85346a7ee07b6e70a
4
+ data.tar.gz: ccabf738ebc176f918eb254e0f70d5a696adc94f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NDgwYTc3MDU4YjE4NDE3Nzg0MTA3OWMzNmZlYzYzNTI0NGEyYTBkMTdhNjIz
10
- ZDdmMzFkMTY2ZWRiNjkyYjBkMTU0MGI5ZGFhM2NhMDE4ODkyMjE1NTJlZTRh
11
- Y2Y0MDliNGRhOTY5NzMzNjJjZmM3MWRiNGQ1ZTNmYzU1MjgyMDE=
12
- data.tar.gz: !binary |-
13
- N2FiNWVjZThhNDE0NzZiMTUzM2MwZjFlYmJlOTk1MDNjNzYzNWI3NTlmOGZl
14
- ODMxZmRhM2NhMmFlZjg0MTZjY2YxNmFhYmI2NzdhMDA0ZDg4NjQ1N2RmZDJk
15
- MTljZjhjYmFiZjY5MWNlMjJhNjA5MTQ3NjUzMDYzMzdlYzg3OTQ=
6
+ metadata.gz: 221241075d5e9e94abf90b6c8da5c86b30e45620d040507478d9bc16c5aff68f9b31717cd87a21b6627b4b55c6ba7de1fb645680bea28102c496840c944838c1
7
+ data.tar.gz: d5998433beff226cae5afadefeb79f9b522179693ea60c185a8366500c6ccc49e6ae940d8dcb6526ed7860af897d70d3d101aebc38a430ee7fa5a58aa88583d5
data/README.md CHANGED
@@ -51,6 +51,19 @@ a single require.
51
51
 
52
52
  require 'dogeify/all'
53
53
 
54
+ ### Options
55
+
56
+ For each of the above method calls, an optional `options` hash can be passed in
57
+ to specify additional processing preferences. Currently, only the `ignore`
58
+ option exists, accepting a string/regex value (or array of string/regex values)
59
+ that should not be converted to doge.
60
+
61
+ dogifier.process('My grandmom gave me a sweater for Christmas.', ignore: 'grandmom')
62
+ # => "so sweater. such christmas. wow."
63
+
64
+ 'My grandmom gave me a sweater for Christmas'.dogeify(ignore: [/christmas/i, 'sweater'])
65
+ # => "so grandmom. wow."
66
+
54
67
  ## Contributing
55
68
 
56
69
  1. Fork it
@@ -9,11 +9,14 @@ class Dogeify
9
9
  @tagger = EngTagger.new
10
10
  end
11
11
 
12
- def process(str)
12
+ def process(str, options = {})
13
13
  # Parse sentences.
14
14
  sentences = str.downcase.split(/[\.!?]+/).map(&:strip)
15
15
 
16
16
  sentences = sentences.map do |sentence|
17
+ # Ignore any provided patterns.
18
+ sentence = ignore_patterns(sentence, options[:ignore]) if options[:ignore]
19
+
17
20
  # Select just the nouns.
18
21
  tagged_sentence = tagger.add_tags(sentence)
19
22
  phrases = tagger.get_nouns(tagged_sentence).keys rescue []
@@ -46,6 +49,12 @@ class Dogeify
46
49
  end
47
50
  end
48
51
 
52
+ def ignore_patterns(sentence, patterns)
53
+ sentence.dup.tap do |sentence|
54
+ Array(patterns).map { |pattern| sentence.gsub!(pattern, '') }
55
+ end
56
+ end
57
+
49
58
  def adjective
50
59
  ADJECTIVES[adjective_offset]
51
60
  end
@@ -1,8 +1,8 @@
1
1
  require 'dogeify'
2
2
 
3
3
  class Array
4
- def dogeify
4
+ def dogeify(options = {})
5
5
  dogeify = Dogeify.new
6
- map { |item| dogeify.process(item.to_s) }
6
+ map { |item| dogeify.process(item.to_s, options) }
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  require 'dogeify'
2
2
 
3
3
  class String
4
- def dogeify
5
- Dogeify.new.process(self)
4
+ def dogeify(options = {})
5
+ Dogeify.new.process(self, options)
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  class Dogeify
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -4,17 +4,19 @@ describe Array do
4
4
  subject { ['My grandmom gave me a sweater for Christmas.', 'I like turtles.', 'I am a banana.'] }
5
5
 
6
6
  describe '#dogeify' do
7
+ let(:options) { { ignore: [] } }
8
+ let(:output) { subject.dogeify(options) }
9
+
7
10
  it 'delegates to Dogeify#process for each element' do
8
11
  subject.each do |item|
9
- expect_any_instance_of(Dogeify).to receive(:process).with(item).once
12
+ expect_any_instance_of(Dogeify).to receive(:process).with(item, options).once
10
13
  end
11
14
 
12
- subject.dogeify
15
+ output
13
16
  end
14
17
 
15
18
  it 'returns an array of strings' do
16
- expect(subject.dogeify).to be_an Array
17
- expect(subject.dogeify.map(&:class).uniq).to eq [String]
19
+ expect(output).to be_an_array_of String
18
20
  end
19
21
  end
20
22
  end
@@ -4,13 +4,16 @@ describe String do
4
4
  subject { 'My grandmom gave me a sweater for Christmas.' }
5
5
 
6
6
  describe '#dogeify' do
7
+ let(:options) { { ignore: [] } }
8
+ let(:output) { subject.dogeify(options) }
9
+
7
10
  it 'delegates to Dogeify#process' do
8
- expect_any_instance_of(Dogeify).to receive(:process).with(subject)
9
- subject.dogeify
11
+ expect_any_instance_of(Dogeify).to receive(:process).with(subject, options)
12
+ output
10
13
  end
11
14
 
12
15
  it 'returns a string' do
13
- expect(subject.dogeify).to be_a String
16
+ expect(output).to be_a String
14
17
  end
15
18
  end
16
19
  end
@@ -55,5 +55,26 @@ describe Dogeify do
55
55
  expect(output).to include 'queschun'
56
56
  end
57
57
  end
58
+
59
+ describe 'when an ignore option is passed' do
60
+ let(:input) { '\e[35;47mHello world!\e[0m' }
61
+ let(:pattern) { /\\e\[\d+(;\d+)?m/ }
62
+
63
+ describe 'with a single pattern' do
64
+ let(:output) { subject.process(input, ignore: pattern) }
65
+
66
+ it 'removes the pattern' do
67
+ expect(output).to start_with 'so world.'
68
+ end
69
+ end
70
+
71
+ describe 'with multiple patterns' do
72
+ let(:output) { subject.process(input, ignore: [pattern, /world/]) }
73
+
74
+ it 'removes all patterns' do
75
+ expect(output).to start_with 'wow.'
76
+ end
77
+ end
78
+ end
58
79
  end
59
80
  end
@@ -1 +1,10 @@
1
1
  require 'dogeify/all'
2
+
3
+ # Requires supporting ruby files with custom matchers and macros, etc, in
4
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
5
+ # run as spec files by default. This means that files in spec/support that end
6
+ # in _spec.rb will both be required and run as specs, causing the specs to be
7
+ # run twice. It is recommended that you do not name files matching this glob to
8
+ # end with _spec.rb. You can configure this pattern with with the --pattern
9
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
10
+ Dir[File.expand_path('spec/support/**/*.rb')].each(&method(:require)) #{ |f| require f }
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :be_an_array_of do |expected|
2
+ match do |actual|
3
+ actual.is_a?(Array) && actual.map(&:class).uniq == [expected]
4
+ end
5
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogeify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Huggins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: engtagger
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,28 +42,28 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Convert everyday boring English into doge speak!
@@ -93,6 +93,7 @@ files:
93
93
  - spec/core_ext/string_spec.rb
94
94
  - spec/dogeify_spec.rb
95
95
  - spec/spec_helper.rb
96
+ - spec/support/matchers/enumerable_matchers.rb
96
97
  - tasks/debug.rake
97
98
  - tasks/rspec.rake
98
99
  homepage: ''
@@ -105,17 +106,17 @@ require_paths:
105
106
  - lib
106
107
  required_ruby_version: !ruby/object:Gem::Requirement
107
108
  requirements:
108
- - - ! '>='
109
+ - - '>='
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  requirements:
113
- - - ! '>='
114
+ - - '>='
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  requirements: []
117
118
  rubyforge_project:
118
- rubygems_version: 2.2.1
119
+ rubygems_version: 2.2.2
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: English to doge translations
@@ -124,3 +125,4 @@ test_files:
124
125
  - spec/core_ext/string_spec.rb
125
126
  - spec/dogeify_spec.rb
126
127
  - spec/spec_helper.rb
128
+ - spec/support/matchers/enumerable_matchers.rb