Sha256: 7b1640321a8ea431d60cd24a3f0946c216f0f937ea8bb692de972a7fa5c3dcb1

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

# frozen_string_literal: true
class ContentSpinning

  class Sentence < ::Array

    def initialize(*items)
      push(*items)
    end

    def cleaned
      map!(&:cleaned)

      case length
      when 0
        ::ContentSpinning::String.new("")
      when 1
        first
      else
        self
      end
    end

    def count
      case length
      when 0
        1
      else
        map(&:count).inject(:*)
      end
    end

    def inspect
      "<Sentence [#{map(&:inspect).join(", ")}]>"
    end

    def random
      map(&:random).join
    end

    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

    def to_source
      map(&:to_source).join
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
content_spinning-0.3.1 lib/content_spinning/sentence.rb