content_spinning 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/content_spinning.rb +38 -25
- data/lib/content_spinning/core_ext/string.rb +1 -0
- data/lib/content_spinning/sentence.rb +1 -0
- data/lib/content_spinning/spinner.rb +1 -0
- data/lib/content_spinning/string.rb +1 -0
- data/lib/content_spinning/version.rb +2 -1
- data/spec/content_spinning/core_ext/string_spec.rb +1 -0
- data/spec/content_spinning_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40f5603ef42234928b5a79823f5e1dcb3dafbe83
|
4
|
+
data.tar.gz: ea05dd01a609b4071e9a184ae2e33484943aeda6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be82438bb2c4cbb4f1329255ee0b560871dc88db4cca82b07f9286a1b5b061d1d87147d66a1e12fdf08b8f23111151e9a0b4566d4f67fcca1b36b6c24b56df51
|
7
|
+
data.tar.gz: 5dee876c19daa4a780b6cbdbc212a29533250cbf45331964938558ed5f2c6c0eb644ebb23c00d37aa641ffdd5b5dc7b620ed3f2b3b79d1d5a0a40c91a9a16605
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Content Spinning
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/content_spinning.svg)](https://badge.fury.io/rb/content_spinning) [![Build Status](https://travis-ci.org/maximeg/content_spinning.svg?branch=master)](https://travis-ci.org/maximeg/content_spinning)
|
4
|
+
|
3
5
|
`ContentSpinning` is a ruby library made to spin some text.
|
4
6
|
It manages nested spinning.
|
5
7
|
|
data/lib/content_spinning.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "content_spinning/core_ext/string"
|
2
3
|
require "content_spinning/sentence"
|
3
4
|
require "content_spinning/spinner"
|
@@ -30,30 +31,18 @@ class ContentSpinning
|
|
30
31
|
def parse
|
31
32
|
return @root if defined?(@root)
|
32
33
|
|
33
|
-
heap = [Sentence.new]
|
34
|
+
heap = [::ContentSpinning::Sentence.new]
|
34
35
|
|
35
36
|
source.scan(/ [{}|] | [^{}|]+ /x).each do |part|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
sentence = ::ContentSpinning::Sentence.new
|
44
|
-
spinner << sentence
|
45
|
-
heap << sentence
|
46
|
-
elsif part == SPIN_OR
|
47
|
-
heap.pop
|
48
|
-
spinner = heap.last
|
49
|
-
sentence = ::ContentSpinning::Sentence.new
|
50
|
-
spinner << sentence
|
51
|
-
heap << sentence
|
52
|
-
elsif part == SPIN_END
|
53
|
-
heap.pop
|
54
|
-
heap.pop
|
37
|
+
case part
|
38
|
+
when SPIN_START
|
39
|
+
modify_heap_for_spin_start(heap)
|
40
|
+
when SPIN_OR
|
41
|
+
modify_heap_for_spin_or(heap)
|
42
|
+
when SPIN_END
|
43
|
+
modify_heap_for_spin_end(heap)
|
55
44
|
else
|
56
|
-
|
45
|
+
heap.last << ::ContentSpinning::String.new(part)
|
57
46
|
end
|
58
47
|
end
|
59
48
|
|
@@ -75,14 +64,38 @@ class ContentSpinning
|
|
75
64
|
def spin_with_limit(limit:)
|
76
65
|
parsed = parse
|
77
66
|
|
78
|
-
|
79
|
-
results.map! do
|
80
|
-
parsed.random
|
81
|
-
end
|
67
|
+
Array.new(limit) { parsed.random }
|
82
68
|
end
|
83
69
|
|
84
70
|
def to_source
|
85
71
|
parse.to_source
|
86
72
|
end
|
87
73
|
|
74
|
+
private
|
75
|
+
|
76
|
+
def modify_heap_for_spin_end(heap)
|
77
|
+
heap.pop(2)
|
78
|
+
end
|
79
|
+
|
80
|
+
def modify_heap_for_spin_or(heap)
|
81
|
+
heap.pop
|
82
|
+
current_spinner = heap.last
|
83
|
+
|
84
|
+
new_sentence = ::ContentSpinning::Sentence.new
|
85
|
+
current_spinner << new_sentence
|
86
|
+
heap << new_sentence
|
87
|
+
end
|
88
|
+
|
89
|
+
def modify_heap_for_spin_start(heap)
|
90
|
+
current = heap.last
|
91
|
+
|
92
|
+
new_spinner = ::ContentSpinning::Spinner.new
|
93
|
+
current << new_spinner
|
94
|
+
heap << new_spinner
|
95
|
+
|
96
|
+
new_sentence = ::ContentSpinning::Sentence.new
|
97
|
+
new_spinner << new_sentence
|
98
|
+
heap << new_sentence
|
99
|
+
end
|
100
|
+
|
88
101
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe ContentSpinning do
|
4
|
-
|
5
5
|
describe "#count" do
|
6
6
|
it "returns an array" do
|
7
7
|
expect(ContentSpinning.new("AaBb").count).to eq(1)
|
@@ -182,7 +182,7 @@ describe ContentSpinning do
|
|
182
182
|
}.not_to change { source }
|
183
183
|
end
|
184
184
|
|
185
|
-
context
|
185
|
+
context "with limit" do
|
186
186
|
before { @old_seed = Random.srand(2736) }
|
187
187
|
after { Random.srand(@old_seed) }
|
188
188
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: content_spinning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxime Garcia
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: 1.3.6
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.6.
|
74
|
+
rubygems_version: 2.6.10
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: Content Spinning
|