Sha256: 5b16aa2f725d42d4edbbfc75df3e9c1a21ff327afce17566735ea430914ab898

Contents?: true

Size: 556 Bytes

Versions: 2

Compression:

Stored size: 556 Bytes

Contents

module SeoFriendly
  class WordsSplitter

    def self.split(object, maximal_length, maximal_words_count)
      if object.length <= maximal_length && words_count(object) <= maximal_words_count
        return object
      else
        object = reduce_string(object)
        split(object, maximal_length, maximal_words_count)
      end
    end

    private

    def self.words_count(object)
      object.split.count
    end

    def self.reduce_string(object)
      array = object.split
      array.delete(array.last)
      array.join(' ')
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
seo_friendly-0.0.2 lib/seo_friendly/words_splitter.rb
seo_friendly-0.0.1 lib/seo_friendly/words_splitter.rb