spintax_parser 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,11 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in spintax_parser.gemspec
4
4
  gemspec
5
5
 
6
- group :development do
7
- gem 'rb-inotify', '~> 0.8.8'
8
- gem 'libnotify', '~> 0.7.4'
9
- end
10
-
11
6
  group :test do
12
7
  gem 'rake'
13
8
  end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SpintaxParser [![Build Status](https://secure.travis-ci.org/flintinatux/spintax_parser.png)](http://travis-ci.org/flintinatux/spintax_parser) [![Dependency Status](https://gemnasium.com/flintinatux/spintax_parser.png)](https://gemnasium.com/flintinatux/spintax_parser) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/flintinatux/spintax_parser)
2
2
 
3
- A mixin to parse "spintax", a text format used for automated article generation. Can handle nested spintax.
3
+ A mixin to parse "spintax", a text format used for automated article generation. Can handle nested spintax, and can count the total number of unique variations.
4
4
 
5
5
  Read more about the motivation behind it at [the announcement of its initial release](http://madhackerdesigns.com/spintax_parser-gem-v0-0-1-released/ "spintax_parser gem v0.0.1 released").
6
6
 
@@ -58,6 +58,13 @@ And don't worry: calling `unspin` on a string with no spintax will safely return
58
58
 
59
59
  Also, note that the `unspin` method doesn't really care if the class you mix it into is a descendant of String or not, as long as its `to_s` method returns a string written in spintax.
60
60
 
61
+ Now you can also count the total number of unique variations of a spintax string. If you've mixed the SpintaxParser into your String class like above, just call the `count_spintax_variations` method on any string as shown below:
62
+
63
+ ```ruby
64
+ spintext = "{Hello|Hi} {{world|worlds}|planet}{!|.|?}"
65
+ puts spintext.count_spintax_variations # => 18
66
+ ```
67
+
61
68
  ## Contributing
62
69
 
63
70
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module SpintaxParser
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -6,11 +6,23 @@ module SpintaxParser
6
6
  SPINTAX_PATTERN = %r/\{([^{}]*)\}/
7
7
 
8
8
  def unspin
9
- spun = clone.to_s
9
+ spun = dup.to_s
10
10
  while spun =~ SPINTAX_PATTERN
11
11
  spun.gsub!(SPINTAX_PATTERN) { $1.split('|').sample }
12
12
  end
13
13
  spun
14
14
  end
15
15
 
16
+ def count_spintax_variations
17
+ spun = dup.to_s
18
+ spun.gsub! %r/[^{|}]+/, '1'
19
+ spun.gsub! %r/\{/, '('
20
+ spun.gsub! %r/\|/, '+'
21
+ spun.gsub! %r/\}/, ')'
22
+ spun.gsub! %r/\)\(/, ')*('
23
+ spun.gsub! %r/\)1/, ')*1'
24
+ spun.gsub! %r/1\(/, '1*('
25
+ eval spun
26
+ end
27
+
16
28
  end # SpintaxParser
@@ -36,4 +36,12 @@ describe SpintaxParser do
36
36
  it { should_not =~ spintax_pattern }
37
37
  end
38
38
  end
39
+
40
+ it "should count spun variations correctly" do
41
+ 'one {two|three} four'.count_spintax_variations.should eq 2
42
+ '{one|two {three|four}} five'.count_spintax_variations.should eq 3
43
+ '{one|two} three {four|five}'.count_spintax_variations.should eq 4
44
+ 'one {{two|three} four|five {six|seven}} eight {nine|ten}'.count_spintax_variations.should eq 8
45
+ '{Hello|Hi} {{world|worlds}|planet}{!|.|?}'.count_spintax_variations.should eq 18
46
+ end
39
47
  end
@@ -4,7 +4,7 @@ require File.expand_path('../lib/spintax_parser/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Scott McCormack"]
6
6
  gem.email = ["mail@madhackerdesigns.com"]
7
- gem.description = %q{A mixin to parse "spintax", a text format used for automated article generation. Can handle nested spintax.}
7
+ gem.description = %q{A mixin to parse "spintax", a text format used for automated article generation. Can handle nested spintax, and can count the total number of unique variations.}
8
8
  gem.summary = gem.description
9
9
  gem.homepage = "https://github.com/flintinatux/spintax_parser"
10
10
 
@@ -16,6 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = SpintaxParser::VERSION
17
17
 
18
18
  gem.add_dependency 'backports'
19
- gem.add_development_dependency 'rspec', '~> 2.11.0'
20
- gem.add_development_dependency 'guard-rspec', '~> 2.0.0'
19
+ gem.add_development_dependency 'rspec', '~> 2.12.0'
21
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spintax_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-30 00:00:00.000000000 Z
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: backports
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.11.0
37
+ version: 2.12.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,25 +42,10 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.11.0
46
- - !ruby/object:Gem::Dependency
47
- name: guard-rspec
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 2.0.0
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 2.0.0
45
+ version: 2.12.0
62
46
  description: A mixin to parse "spintax", a text format used for automated article
63
- generation. Can handle nested spintax.
47
+ generation. Can handle nested spintax, and can count the total number of unique
48
+ variations.
64
49
  email:
65
50
  - mail@madhackerdesigns.com
66
51
  executables: []
@@ -70,7 +55,6 @@ files:
70
55
  - .gitignore
71
56
  - .travis.yml
72
57
  - Gemfile
73
- - Guardfile
74
58
  - LICENSE
75
59
  - README.md
76
60
  - Rakefile
@@ -92,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
76
  version: '0'
93
77
  segments:
94
78
  - 0
95
- hash: -2003280369661197721
79
+ hash: 4151852987598141644
96
80
  required_rubygems_version: !ruby/object:Gem::Requirement
97
81
  none: false
98
82
  requirements:
@@ -101,13 +85,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
85
  version: '0'
102
86
  segments:
103
87
  - 0
104
- hash: -2003280369661197721
88
+ hash: 4151852987598141644
105
89
  requirements: []
106
90
  rubyforge_project:
107
91
  rubygems_version: 1.8.24
108
92
  signing_key:
109
93
  specification_version: 3
110
94
  summary: A mixin to parse "spintax", a text format used for automated article generation.
111
- Can handle nested spintax.
95
+ Can handle nested spintax, and can count the total number of unique variations.
112
96
  test_files:
113
97
  - spec/lib/spintax_parser_spec.rb
data/Guardfile DELETED
@@ -1,24 +0,0 @@
1
- # Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec' do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
-
9
- # Rails example
10
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
- watch('config/routes.rb') { "spec/routing" }
15
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
-
17
- # Capybara request specs
18
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
-
20
- # Turnip features and steps
21
- watch(%r{^spec/acceptance/(.+)\.feature$})
22
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
- end
24
-