Project

stubber

0.0
No commit activity in last 3 years
No release in over 3 years
Stubber allows you to truncate Strings, while preserving whole-words.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.4

Runtime

~> 0.6
 Project Readme

Stubber

Stubber is a simple gem that lets you stub strings, using "words" as the unit of measure. For example:

    require 'stubber'
    require 'lorem' # Or just add your own text

    str = Lorem::Base.new('paragraphs', 1).output
    # => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus vitae risus vitae lorem iaculis placerat."

    # Get the first 5 words
    str.stub_words(5)
    # => "Lorem ipsum dolor sit amet"

    # Get the NEXT 5 words
    str.stub_words(5, true)
    # => ", consectetuer adipiscing elit. Vivamus vitae"

    # Grab the _complete_ words, appearing _up to_ position 70
    str.stub_to(70)
    # => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus "

    str.stub_to(70).size
    # => 66

    # Grab the _complete_ words, appearing _through_ position 70
    str.stub_thru(70)
    # => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus vitae"

    str.stub_thru(70).size
    # => 71

Now the other direction!

    str.stub_words(-5)
    # => "risus vitae lorem iaculis placerat."

    str.stub_words(-5, true)
    # => "consectetuer adipiscing elit. Vivamus vitae "

    str.stub_to(-45)
    # => " vitae risus vitae lorem iaculis placerat."

    str.stub_to(-45).size
    # => 42

So far, so good! Suggestions are welcome.

TODO

  • stubbing from the right direction is simple to do and will be the next addition.
    • ^ done, needs specs
  • left and right indexes