Module: Truncato

Defined in:
lib/truncato/truncato.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
    max_length: 30,
    count_tags: true,
    tail: "..."
}

Class Method Summary collapse

Class Method Details

.truncate(source, user_options = {}) ⇒ String

Truncates the source XML string and returns the result

Parameters:

  • source (String)

    the XML source to truncate

  • user_options (Hash) (defaults to: {})

    truncation options

Options Hash (user_options):

  • :max_length (Integer)

    Maximum length

  • :tail (String)

    text to append when the truncation occurs

  • :count_tags (Boolean)

    ‘true` for counting tags for truncation, `false` for not counting them

Returns:

  • (String)

    the truncated string



16
17
18
19
# File 'lib/truncato/truncato.rb', line 16

def self.truncate source, user_options={}
  options = DEFAULT_OPTIONS.merge(user_options)
  self.truncate_html(source, options) || self.truncate_no_html(source, options)
end