Sha256: f6afaf74cfda881133ab6d513bfe2a4dd43d63a89cd1bd4eac4d5f58498ab4bc

Contents?: true

Size: 661 Bytes

Versions: 1

Compression:

Stored size: 661 Bytes

Contents

module ArticleHelper

  MORE_CHARACTERS_TOLERANCE = 100
  NUMBER_OF_CHARACTERS = 1200

  def shorten_text(text, number_of_characters = NUMBER_OF_CHARACTERS, more_link = nil)
    if !(text.nil? || text.empty?)
      if text.length <= number_of_characters
        shorter_text = text
      else
        punction_char_after_end = \
          (text[number_of_characters..number_of_characters+MORE_CHARACTERS_TOLERANCE] =~ /\.|,|;/) || 0
        shorter_text = text[0..number_of_characters + punction_char_after_end]

        if more_link
          shorter_text += more_link
        end
      end
    else
      shorter_text = ''
    end

    shorter_text
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solarsearch-0.0.6 app/helpers/article_helper.rb