spintax_parser 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  bundler_stubs/
19
+ .ruby-version
data/.travis.yml CHANGED
@@ -4,9 +4,9 @@ rvm:
4
4
  - "1.9.2"
5
5
  - "1.9.3"
6
6
  - jruby-18mode # JRuby in 1.8 mode
7
- - jruby-19mode # JRuby in 1.9 mode
7
+ # - jruby-19mode # JRuby in 1.9 mode throws some error about Random
8
8
  - rbx-18mode
9
9
  - rbx-19mode
10
10
  - ree
11
11
  # uncomment this line if your project needs to run something other than `rake`:
12
- # script: bundle exec rspec spec
12
+ # script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,6 +1,6 @@
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)
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/github/flintinatux/spintax_parser.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, and can count the total number of unique variations.
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. Now also supports [consistent unspinning](#consistent-unspinning)!
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
 
@@ -22,17 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Perhaps the simplest way to use it is to mix SpintaxParser directly into the global String class, like this:
25
+ Perhaps the simplest way to use it is to mix `SpintaxParser` directly into the global `String` class, like this:
26
26
 
27
27
  ```ruby
28
28
  require 'spintax_parser'
29
-
30
29
  class String
31
30
  include SpintaxParser
32
31
  end
33
32
  ```
34
33
 
35
- Then you can safely call `unspin` on any string in your application:
34
+ Then you can safely call `#unspin` on any string in your application:
36
35
 
37
36
  ```ruby
38
37
  spintext = "{Hello|Hi} {{world|worlds}|planet}{!|.|?}"
@@ -54,15 +53,27 @@ Run the code above, and you will end up with several random variations of the sa
54
53
  Hello world!
55
54
  Hello worlds.
56
55
 
57
- And don't worry: calling `unspin` on a string with no spintax will safely return an unaffected copy of the string.
56
+ And don't worry: calling `#unspin` on a string with no spintax will safely return an unaffected copy of the string.
57
+
58
+ 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.
59
+
60
+ ### Consistent unspinning
61
+
62
+ Got a special project that requires unspinning the same spintax the same way in certain circumstances? No problem. If you're using a Ruby version >= 1.9.3, you can pass a pre-seeded random number generator to the `#unspin` method just like you would to the `Array#sample` method. Et voila! Consistent unspinning!
63
+
64
+ ```ruby
65
+ seed = Random.new_seed
66
+ spintext.unspin :random => Random.new(seed) # => "Hello world!"
67
+ spintext.unspin :random => Random.new(seed) # => "Hello world!"
68
+ ```
58
69
 
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.
70
+ ### Counting total variations
60
71
 
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:
72
+ 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
73
 
63
74
  ```ruby
64
75
  spintext = "{Hello|Hi} {{world|worlds}|planet}{!|.|?}"
65
- puts spintext.count_spintax_variations # => 18
76
+ spintext.count_spintax_variations # => 18
66
77
  ```
67
78
 
68
79
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  module SpintaxParser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,14 +1,14 @@
1
- require "spintax_parser/version"
2
- require "backports" if RUBY_VERSION < "1.9"
1
+ require 'spintax_parser/version'
2
+ require 'backports/1.9.1/array/sample' if RUBY_VERSION < '1.9.1'
3
3
 
4
4
  module SpintaxParser
5
5
 
6
6
  SPINTAX_PATTERN = %r/\{([^{}]*)\}/
7
7
 
8
- def unspin
8
+ def unspin(options={})
9
9
  spun = dup.to_s
10
10
  while spun =~ SPINTAX_PATTERN
11
- spun.gsub!(SPINTAX_PATTERN) { $1.split('|').sample }
11
+ parse_the_spintax_in spun, options
12
12
  end
13
13
  spun
14
14
  end
@@ -25,4 +25,15 @@ module SpintaxParser
25
25
  eval spun
26
26
  end
27
27
 
28
- end # SpintaxParser
28
+ private
29
+
30
+ if RUBY_VERSION >= '1.9.3'
31
+ def parse_the_spintax_in(spun, options={})
32
+ spun.gsub!(SPINTAX_PATTERN) { $1.split('|').sample(options) }
33
+ end
34
+ else
35
+ def parse_the_spintax_in(spun, options={})
36
+ spun.gsub!(SPINTAX_PATTERN) { $1.split('|').sample }
37
+ end
38
+ end
39
+ end
@@ -12,21 +12,19 @@ describe SpintaxParser do
12
12
 
13
13
  describe "calling unspin" do
14
14
 
15
- describe "on plaintext" do
16
-
17
- it "should not change the plaintext" do
15
+ context "on plaintext" do
16
+ it "does not change the plaintext" do
18
17
  expect { plaintext.unspin }.not_to change { plaintext }
19
18
  end
20
19
 
21
20
  let(:result) { plaintext.unspin }
22
- it "should return the same plaintext" do
21
+ it "returns the same plaintext" do
23
22
  result.should == plaintext
24
23
  end
25
24
  end
26
25
 
27
- describe "on spintext" do
28
-
29
- it "should not change the spintext" do
26
+ context "on spintext" do
27
+ it "does not change the spintext" do
30
28
  expect { spintext.unspin }.not_to change { spintext }
31
29
  end
32
30
 
@@ -35,6 +33,17 @@ describe SpintaxParser do
35
33
  it { should_not == spintext }
36
34
  it { should_not =~ spintax_pattern }
37
35
  end
36
+
37
+ if RUBY_VERSION >= '1.9.3'
38
+ context "with the same rng supplied" do
39
+ it "produces the same unspun version each time" do
40
+ seed = Random.new_seed
41
+ unspun1 = spintext.unspin :random => Random.new(seed)
42
+ unspun2 = spintext.unspin :random => Random.new(seed)
43
+ unspun1.should eq unspun2
44
+ end
45
+ end
46
+ end
38
47
  end
39
48
 
40
49
  it "should count spun variations correctly" do
@@ -44,4 +53,4 @@ describe SpintaxParser do
44
53
  'one {{two|three} four|five {six|seven}} eight {nine|ten}'.count_spintax_variations.should eq 8
45
54
  '{Hello|Hi} {{world|worlds}|planet}{!|.|?}'.count_spintax_variations.should eq 18
46
55
  end
47
- end
56
+ 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, and can count the total number of unique variations.}
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. Now also supports consistent unspinning!}
8
8
  gem.summary = gem.description
9
9
  gem.homepage = "https://github.com/flintinatux/spintax_parser"
10
10
 
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = SpintaxParser::VERSION
17
17
 
18
- gem.add_dependency 'backports'
19
- gem.add_development_dependency 'rspec', '~> 2.12.0'
18
+ gem.add_dependency 'backports', '~> 3.3'
19
+ gem.add_development_dependency 'rspec', '~> 2.12'
20
20
  end
metadata CHANGED
@@ -1,57 +1,62 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spintax_parser
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Scott McCormack
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-11-30 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: backports
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
17
+
18
+ date: 2013-05-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
33
22
  none: false
34
- requirements:
23
+ requirements:
35
24
  - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 2.12.0
38
- type: :development
25
+ - !ruby/object:Gem::Version
26
+ hash: 1
27
+ segments:
28
+ - 3
29
+ - 3
30
+ version: "3.3"
31
+ name: backports
39
32
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
33
+ type: :runtime
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
37
  none: false
42
- requirements:
38
+ requirements:
43
39
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 2.12.0
46
- description: A mixin to parse "spintax", a text format used for automated article
47
- generation. Can handle nested spintax, and can count the total number of unique
48
- variations.
49
- email:
40
+ - !ruby/object:Gem::Version
41
+ hash: 27
42
+ segments:
43
+ - 2
44
+ - 12
45
+ version: "2.12"
46
+ name: rspec
47
+ prerelease: false
48
+ type: :development
49
+ requirement: *id002
50
+ description: 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. Now also supports consistent unspinning!
51
+ email:
50
52
  - mail@madhackerdesigns.com
51
53
  executables: []
54
+
52
55
  extensions: []
56
+
53
57
  extra_rdoc_files: []
54
- files:
58
+
59
+ files:
55
60
  - .gitignore
56
61
  - .travis.yml
57
62
  - Gemfile
@@ -64,34 +69,36 @@ files:
64
69
  - spintax_parser.gemspec
65
70
  homepage: https://github.com/flintinatux/spintax_parser
66
71
  licenses: []
72
+
67
73
  post_install_message:
68
74
  rdoc_options: []
69
- require_paths:
75
+
76
+ require_paths:
70
77
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
72
79
  none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- segments:
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
78
85
  - 0
79
- hash: 4151852987598141644
80
- required_rubygems_version: !ruby/object:Gem::Requirement
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
88
  none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- segments:
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
87
94
  - 0
88
- hash: 4151852987598141644
95
+ version: "0"
89
96
  requirements: []
97
+
90
98
  rubyforge_project:
91
- rubygems_version: 1.8.24
99
+ rubygems_version: 1.8.25
92
100
  signing_key:
93
101
  specification_version: 3
94
- summary: A mixin to parse "spintax", a text format used for automated article generation.
95
- Can handle nested spintax, and can count the total number of unique variations.
96
- test_files:
102
+ summary: 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. Now also supports consistent unspinning!
103
+ test_files:
97
104
  - spec/lib/spintax_parser_spec.rb