content_spinning 0.3.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 725d38ecb0875c5f125823a80e16105d65875327
4
- data.tar.gz: feaff568e498f301547e05d5472e7ff4dd9ea4f0
3
+ metadata.gz: 40f5603ef42234928b5a79823f5e1dcb3dafbe83
4
+ data.tar.gz: ea05dd01a609b4071e9a184ae2e33484943aeda6
5
5
  SHA512:
6
- metadata.gz: 1a1c3bfcd8dc80d0690326333d197e6f4ddae3f19e09abad7d318dddcece9c42be5e4d1448bef2eec17ac59335b6ae2de892fa548ea2bc89107952641d2ebd36
7
- data.tar.gz: 51550db06f73c46870dfaedc4e90bf913b5cd8f4fbb0b2064d3b6e3bca77b7bf8480633a51f12325d3b4d5d12f2d774a9314a8afebf6966c4d5c52b69715dc57
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
 
@@ -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
- current = heap.last
37
-
38
- if part == SPIN_START
39
- spinner = ::ContentSpinning::Spinner.new
40
- current << spinner
41
- heap << spinner
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
- current << ::ContentSpinning::String.new(part)
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
- results = Array.new(limit)
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,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class String
2
3
 
3
4
  def spin(limit: nil)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class ContentSpinning
2
3
 
3
4
  class Sentence < ::Array
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class ContentSpinning
2
3
 
3
4
  class Spinner < ::Array
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class ContentSpinning
2
3
 
3
4
  class String < ::String
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  class ContentSpinning
2
3
 
3
4
  module Version
4
5
 
5
- STRING = "0.3.0".freeze
6
+ STRING = "0.3.1"
6
7
 
7
8
  end
8
9
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "spec_helper"
2
3
 
3
4
  describe String do
@@ -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 'with limit' do
185
+ context "with limit" do
186
186
  before { @old_seed = Random.srand(2736) }
187
187
  after { Random.srand(@old_seed) }
188
188
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "rspec"
2
3
  require "content_spinning"
3
4
 
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.0
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.8
74
+ rubygems_version: 2.6.10
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Content Spinning