Project

yesno

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Boolean helper fot rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0
 Project Readme

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