Skip to content

gemsbyed/sanetitle

Repository files navigation

SaneTitle

GitHub version Build status Code Climate Issue Count

This gem generates a sane hyfen-separated text to serve as URL address to a page, based on a given string. It is ideal to generate a URL based on a title of a blog post or article, thus the name of the gem.

Installation

Add this line to your application's Gemfile:

gem 'sanetitle'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install sanetitle

Usage

The usage is quite simple.

Just create a SaneTitle::Sanitize object, passing the string you want to make sane, like:

    obj = SaneTitle::Sanifier.new("Este é um exemplo de string que será corrigida no curso da programação")

and then store the sane string in a variable with

    sane_title = obj.result

In this particular case, the variable sane_title shall contain "este-e-um-exemplo-de-string-que-sera-corrigida-no-curso-da-programacao".

From release 0.3.0 on, one may also call

    sane_title = obj.result_imp(<limit>,<html>,<tstamp>)

where:

is an integer value used to require that the size of the result string is limited to this size, and

is a boolean value to require (true) or not (false) that the extension .html is appended to the result. is a boolean value to indicating if the result string must be prepended with a timestamp in the format "yyyy-mm-dd-hh-mm-ss-"

Note two important things:

  1. If you use
    sane_title = obj.result_imp(20,true)

the result string shall have, in fact, a lenght of 25. 20 from the limit you asked, plus five, which is the size of the extension .html. If you want a total of 20 positions you should say

    sane_title = obj.result_imp(15,true)

Important advice

This gem makes no assumption about filesystems. Then, if you intend to use the filename obtained here as a name of a file to be written, please take care of duplicate names before writing. We won't accept any responsability on data loss.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Donating

Cosider supporting my work donating some money. This will help me to create more and more useful gems to enrich Ruby's ecosystem.

Contributing

If you want to contribute to this project, your help is welcome, for sure. But please, take some note before you start, so you won't tell me you didn't knew these things beforehand:

  1. We are here to develop some software, not to discuss politics, race, religion, gender or any other issue the 'politically correct' people like to raise to disguise their inability to make things happen.

  2. Opinions given by any developer outside the scope of this project are not our business. We don't care about what what you think, as long as you do NOT bring your opinions to this development space.

  3. You may not raise issues about things not related to this project. This includes issues related to other developer's opinions given outside here.

  4. Just to summarize all things said before: Keep your personal stuff far away from this project and discuss only the project in its context.

License

The gem is available as open source under the terms of the MIT License.