Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

MdreW/yesno

Repository files navigation

Yesno

Yesno is a simple utility for boolean case.

“yesno” is a simple aid for the Boolean case. “yesno” transforms the answers to true / false in various interpretations possible (yes / no, male / female, active / inactive). To use I18n translations and is provided with translations in Italian, English and French.

Install

gem install yesno
rails generate yesno:install

standard implementation

Example:

if @article.active is false

# yesno(@article.active) -> “false” # yesno(@article.active, :type => “atc”) -> “inactive”

if @person.sex is true

# yesno(@person.sex, :type => “mf”) -> “male” # yesno(@person.sex, :type => “mf”, :pluralize => true) -> “man”

the options are

:type => "tipology"
:female => true/false
:pluralize => true/false

the types are

"default" (true/false)
"yn" (yes/no)
"mf" (male/female)
"act" (active/inactive)

fast implementation

Fyesno is a more fast implementation of yesno. Fyesno“ solves the conversion with a single ”if“ using the options to address directly the translation.

# fyesno(to_validate, type, option)

where default type is “default” and default option is “ms”. “option” is a string containing the two letters to this standard:

"ms" masculine singular
"mp" masculine plural
"fs" feminine singular
"fp" feminine plural

Example

if @var.test is true
# fyesno(@var.test) -> "true"
# fyesno(@var.test, "mf", "mp") -> "man"
# fyesno(@var.test, "act", "fp") -> "actives"

extend the types

To add new features just edit the file yesno.#{lang}.yml and add new implementations:

it:
  yesno:
    default:
      smt: "vero"
      smf: "falso"
      sft: "vera"
      sff: "falsa"
      pmt: "veri"
      pmf: "falsi"
      pft: "vere"
      pff: "false"
    yn:
      smt: "si"
      smf: "no"
    ecc.....
  • the type of translation is the third indentation

  • the translation is the fourth indentation

  • the name of the traslation (smt, smf, ecc.) is the declination.

smt single male true smf single male false .. pff pural female false

With this simple rule is possible to implement new uses

This project rocks and uses MIT-LICENSE.

email me if you have new implementations or translations

About

boolean helper for ruby on rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages