Sha256: a30ad53c494643bc99664f300ab2a6536913d737cd4fc706e71fce0a31bd58b0

Contents?: true

Size: 789 Bytes

Versions: 2

Compression:

Stored size: 789 Bytes

Contents

module RandomText
  class RandomText
    def initialize(text)
      @words = RandomStrings.new(text.scan(/\w{3,}/).
              collect{ |w| chars(w).downcase.to_s }.
              reject{ |w| w =~ /^[0-9]/ }.
              uniq.map{ |w| chars(w) })
      @sentences = RandomStrings.new(text.split(/[\r\n]+/).
              map(&:strip).compact.
              delete_if(&:blank?).uniq)
    end

    def chars(s)
      s.respond_to?(:mb_chars) ? s.mb_chars : s.chars
    end

    def word
      @words.get
    end

    def words(n = :all)
      @words.get(n)
    end

    def uniq_words(n = :all)
      @words.uniq(n)
    end
    alias_method :unique_words, :uniq_words

    def sentence
      @sentences.get
    end

    def sentences(n = :all)
      @sentences.get(n)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
random_text-0.0.6.5 lib/random_text/random_text.rb
random_text-0.0.6.4 lib/random_text/random_text.rb