Class: ContentSpinning::Sentence
- Inherits:
-
Array
- Object
- Array
- ContentSpinning::Sentence
- Defined in:
- lib/content_spinning/sentence.rb
Instance Method Summary collapse
- #cleaned ⇒ Object
- #count ⇒ Object
-
#initialize(*items) ⇒ Sentence
constructor
A new instance of Sentence.
- #inspect ⇒ Object
- #random ⇒ Object
- #spin ⇒ Object
- #to_source ⇒ Object
Constructor Details
#initialize(*items) ⇒ Sentence
Returns a new instance of Sentence.
6 7 8 |
# File 'lib/content_spinning/sentence.rb', line 6 def initialize(*items) push(*items) end |
Instance Method Details
#cleaned ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/content_spinning/sentence.rb', line 10 def cleaned map!(&:cleaned) case length when 0 ::ContentSpinning::String.new("") when 1 first else self end end |
#count ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/content_spinning/sentence.rb', line 23 def count case length when 0 1 else map(&:count).inject(:*) end end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/content_spinning/sentence.rb', line 32 def inspect "<Sentence [#{map(&:inspect).join(", ")}]>" end |
#random ⇒ Object
36 37 38 |
# File 'lib/content_spinning/sentence.rb', line 36 def random map(&:random).join end |
#spin ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/content_spinning/sentence.rb', line 40 def spin spinned = map(&:spin) case spinned.length when 1 spinned[0] else spinned[0].product(*spinned[1..-1]).tap do |products| products.map!(&:join) end end end |
#to_source ⇒ Object
53 54 55 |
# File 'lib/content_spinning/sentence.rb', line 53 def to_source map(&:to_source).join end |