# MuchBoolean An API for friendly boolean conversion, interpretation and handling ## Usage ```ruby require "much-boolean" MuchBoolean::FALSE_VALUES # => [ 0, "0", # false, "false", "False", "FALSE", "f", "F", # "no", "No", "NO", "n", "N" # ] # convert human-friendly representative values to actual booleans # nil and empty-string values MuchBoolean.convert(nil) # => false MuchBoolean.convert("") # => false MuchBoolean.convert(:"") # => false # zero/one type values MuchBoolean.convert(0) # => false MuchBoolean.convert("0") # => false MuchBoolean.convert(:"0") # => false MuchBoolean.convert(1) # => true MuchBoolean.convert("1") # => true MuchBoolean.convert(:"1") # => true # true/false type values MuchBoolean.convert(false) # => false MuchBoolean.convert("f") # => false MuchBoolean.convert(:f) # => false MuchBoolean.convert("F") # => false MuchBoolean.convert(:F) # => false MuchBoolean.convert("false") # => false MuchBoolean.convert(:false) # => false MuchBoolean.convert("False") # => false MuchBoolean.convert(:False) # => false MuchBoolean.convert("FALSE") # => false MuchBoolean.convert(:FALSE) # => false MuchBoolean.convert(true) # => true MuchBoolean.convert("t") # => true MuchBoolean.convert(:t) # => true MuchBoolean.convert("T") # => true MuchBoolean.convert(:T) # => true MuchBoolean.convert("true") # => true MuchBoolean.convert(:true) # => true MuchBoolean.convert("True") # => true MuchBoolean.convert(:True) # => true MuchBoolean.convert("TRUE") # => true MuchBoolean.convert(:TRUE) # => true # on/off type values MuchBoolean.convert("off") # => false MuchBoolean.convert(:off) # => false MuchBoolean.convert("Off") # => false MuchBoolean.convert(:Off) # => false MuchBoolean.convert("OFF") # => false MuchBoolean.convert(:OFF) # => false MuchBoolean.convert("on") # => true MuchBoolean.convert(:on) # => true MuchBoolean.convert("On") # => true MuchBoolean.convert(:On) # => true MuchBoolean.convert("ON") # => true MuchBoolean.convert(:ON) # => true # yes/no type values MuchBoolean.convert("n") # => false MuchBoolean.convert(:n) # => false MuchBoolean.convert("N") # => false MuchBoolean.convert(:N) # => false MuchBoolean.convert("no") # => false MuchBoolean.convert(:no) # => false MuchBoolean.convert("No") # => false MuchBoolean.convert(:No) # => false MuchBoolean.convert("NO") # => false MuchBoolean.convert(:NO) # => false MuchBoolean.convert("y") # => true MuchBoolean.convert(:y) # => true MuchBoolean.convert("Y") # => true MuchBoolean.convert(:Y) # => true MuchBoolean.convert("yes") # => true MuchBoolean.convert(:yes) # => true MuchBoolean.convert("Yes") # => true MuchBoolean.convert(:Yes) # => true MuchBoolean.convert("YES") # => true MuchBoolean.convert(:YES) # => true # all other values always interpreted as `true` MuchBoolean.convert("some-string") # => true MuchBoolean.convert(1938) # => true MuchBoolean.convert(1938.5) # => true MuchBoolean.convert(Date.today) # => true MuchBoolean.convert(Time.now) # => true # convert actual booleans back to human-friendly representative values MuchBoolean.one_zero(true) # => 1 MuchBoolean.one_zero(false) # => 0 MuchBoolean.one_zero(true).to_s # => "1" MuchBoolean.one_zero(false).to_s # => "0" MuchBoolean.t_f(true) # => "t" MuchBoolean.t_f(false) # => "f" MuchBoolean.T_F(true) # => "T" MuchBoolean.T_F(false) # => "F" MuchBoolean.true_false(true) # => "true" MuchBoolean.true_false(false) # => "false" MuchBoolean.True_False(true) # => "True" MuchBoolean.True_False(false) # => "False" MuchBoolean.TRUE_FALSE(true) # => "TRUE" MuchBoolean.TRUE_FALSE(false) # => "FALSE" MuchBoolean.on_off(true) # => "on" MuchBoolean.on_off(false) # => "off" MuchBoolean.On_Off(true) # => "On" MuchBoolean.On_Off(false) # => "Off" MuchBoolean.ON_OFF(true) # => "ON" MuchBoolean.ON_OFF(false) # => "OFF" MuchBoolean.y_n(true) # => "y" MuchBoolean.y_n(false) # => "n" MuchBoolean.Y_N(true) # => "Y" MuchBoolean.Y_N(false) # => "N" MuchBoolean.yes_no(true) # => "yes" MuchBoolean.yes_no(false) # => "no" MuchBoolean.Yes_No(true) # => "Yes" MuchBoolean.Yes_No(false) # => "No" MuchBoolean.YES_NO(true) # => "YES" MuchBoolean.YES_NO(false) # => "NO" # create instances to track given human-friendly values and the boolean values they map to bool = MuchBoolean.new bool.given # => nil bool.actual # => nil MuchBoolean::FALSE_VALUES.each do |val| bool = MuchBoolean.new(val) bool.given # => {val} bool.actual # => false bool == false # => true bool == true # => false end ["some-string", 1938, 1938.5, Date.today, Time.now].each do |val| bool = MuchBoolean.new(val) bool.given # => {val} bool.actual # => true bool == true # => true bool == false # => false end ``` ## Installation Add this line to your application's Gemfile: gem "much-boolean" And then execute: $ bundle Or install it yourself as: $ gem install much-boolean ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request