class ContentSpinning::Sentence
Public Class Methods
new(*items)
click to toggle source
# File lib/content_spinning/sentence.rb, line 6 def initialize(*items) push(*items) end
Public Instance Methods
cleaned()
click to toggle source
# 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()
click to toggle source
# File lib/content_spinning/sentence.rb, line 23 def count case length when 0 1 else map(&:count).inject(:*) end end
inspect()
click to toggle source
# File lib/content_spinning/sentence.rb, line 32 def inspect "<Sentence [#{map(&:inspect).join(", ")}]>" end
random()
click to toggle source
# File lib/content_spinning/sentence.rb, line 36 def random map(&:random).join end
spin()
click to toggle source
# 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()
click to toggle source
# File lib/content_spinning/sentence.rb, line 53 def to_source map(&:to_source).join end