spintax_parser 0.0.1
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.
- data/.gitignore +18 -0
- data/.travis.yml +11 -0
- data/Gemfile +13 -0
- data/Guardfile +24 -0
- data/LICENSE +22 -0
- data/README.md +65 -0
- data/Rakefile +9 -0
- data/lib/spintax_parser/version.rb +3 -0
- data/lib/spintax_parser.rb +16 -0
- data/spec/lib/spintax_parser_spec.rb +39 -0
- data/spintax_parser.gemspec +21 -0
- metadata +113 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- "1.8.7"
|
4
|
+
- "1.9.2"
|
5
|
+
- "1.9.3"
|
6
|
+
- jruby-18mode # JRuby in 1.8 mode
|
7
|
+
- jruby-19mode # JRuby in 1.9 mode
|
8
|
+
- rbx-18mode
|
9
|
+
- rbx-19mode
|
10
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
11
|
+
# script: bundle exec rspec spec
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 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
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Scott McCormack
|
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,65 @@
|
|
1
|
+
# SpintaxParser [](http://travis-ci.org/flintinatux/spintax_parser) [](https://gemnasium.com/flintinatux/spintax_parser) [](https://codeclimate.com/github/flintinatux/spintax_parser)
|
2
|
+
|
3
|
+
A mixin to parse "spintax", a text format used for automated article generation. Can handle nested spintax.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'spintax_parser'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install spintax_parser
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Perhaps the simplest way to use it is to mix SpintaxParser directly into the global String class, like this:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'spintax_parser'
|
27
|
+
|
28
|
+
class String
|
29
|
+
include SpintaxParser
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Then you can safely call `unspin` on any string in your application:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
spintext = "{Hello|Hi} {{world|worlds}|planet}{!|.|?}"
|
37
|
+
10.times do
|
38
|
+
puts spintext.unspin
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Run the code above, and you will end up with several random variations of the same text, such as:
|
43
|
+
|
44
|
+
Hi worlds.
|
45
|
+
Hi planet?
|
46
|
+
Hello world?
|
47
|
+
Hi planet?
|
48
|
+
Hi world?
|
49
|
+
Hi world!
|
50
|
+
Hi world.
|
51
|
+
Hello world.
|
52
|
+
Hello world!
|
53
|
+
Hello worlds.
|
54
|
+
|
55
|
+
And don't worry: calling `unspin` on a string with no spintax will safely return an unaffected copy of the string.
|
56
|
+
|
57
|
+
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.
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spintax_parser/version"
|
2
|
+
require "backports" if RUBY_VERSION < "1.9"
|
3
|
+
|
4
|
+
module SpintaxParser
|
5
|
+
|
6
|
+
SPINTAX_PATTERN = %r/\{([^{}]*)\}/
|
7
|
+
|
8
|
+
def unspin
|
9
|
+
spun = clone.to_s
|
10
|
+
while spun =~ SPINTAX_PATTERN
|
11
|
+
spun.gsub!(SPINTAX_PATTERN) { $1.split('|').sample }
|
12
|
+
end
|
13
|
+
spun
|
14
|
+
end
|
15
|
+
|
16
|
+
end # SpintaxParser
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spintax_parser'
|
2
|
+
|
3
|
+
class String
|
4
|
+
include SpintaxParser
|
5
|
+
end
|
6
|
+
|
7
|
+
describe SpintaxParser do
|
8
|
+
|
9
|
+
let(:plaintext) { 'Hello world.' }
|
10
|
+
let(:spintext) { 'Find this. {Hello|Hi} to the {{world|worlds} out there|planet}{!|.|?} Cool.' }
|
11
|
+
let(:spintax_pattern) { /\{[^{}]*\}/ }
|
12
|
+
|
13
|
+
describe "calling unspin" do
|
14
|
+
|
15
|
+
describe "on plaintext" do
|
16
|
+
|
17
|
+
it "should not change the plaintext" do
|
18
|
+
expect { plaintext.unspin }.not_to change { plaintext }
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:result) { plaintext.unspin }
|
22
|
+
it "should return the same plaintext" do
|
23
|
+
result.should == plaintext
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "on spintext" do
|
28
|
+
|
29
|
+
it "should not change the spintext" do
|
30
|
+
expect { spintext.unspin }.not_to change { spintext }
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:result) { spintext.unspin }
|
34
|
+
subject { result }
|
35
|
+
it { should_not == spintext }
|
36
|
+
it { should_not =~ spintax_pattern }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/spintax_parser/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Scott McCormack"]
|
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.}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = "https://github.com/flintinatux/spintax_parser"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "spintax_parser"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SpintaxParser::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'backports'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 2.11.0'
|
20
|
+
gem.add_development_dependency 'guard-rspec', '~> 1.2.1'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spintax_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scott McCormack
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-18 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
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.11.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
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: 1.2.1
|
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: 1.2.1
|
62
|
+
description: A mixin to parse "spintax", a text format used for automated article
|
63
|
+
generation. Can handle nested spintax.
|
64
|
+
email:
|
65
|
+
- mail@madhackerdesigns.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .travis.yml
|
72
|
+
- Gemfile
|
73
|
+
- Guardfile
|
74
|
+
- LICENSE
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- lib/spintax_parser.rb
|
78
|
+
- lib/spintax_parser/version.rb
|
79
|
+
- spec/lib/spintax_parser_spec.rb
|
80
|
+
- spintax_parser.gemspec
|
81
|
+
homepage: https://github.com/flintinatux/spintax_parser
|
82
|
+
licenses: []
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: -1895077201534751717
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: -1895077201534751717
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.24
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: A mixin to parse "spintax", a text format used for automated article generation.
|
111
|
+
Can handle nested spintax.
|
112
|
+
test_files:
|
113
|
+
- spec/lib/spintax_parser_spec.rb
|