Project

quack

0.0
No commit activity in last 3 years
No release in over 3 years
A simple type coercion library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

Quack

Quack is a simple Ruby scalar type coercion library.

Installation

Add this line to your application's Gemfile:

gem 'quack'

And then execute:

$ bundle

Or install it yourself as:

$ gem install quack

Usage

Quack is able to guess the following type categories and cast values to appropriate built-in type:

  • Integer
  • Float
  • Time
  • Boolean
  • Null
  • String

Integer

value = Quack("123")
value.class
#=> Quack::Types::Integer
value.to_coerced
#=> 123
value.to_coerced.class
#=> Integer

Integer (Ruby 2.3 and earlier)

value = Quack("123")
value.class
#=> Quack::Types::Integer
value.to_coerced
#=> 123
value.to_coerced.class
#=> Fixnum

Float

value = Quack("29.4")
value.class
#=> Quack::Types::Float
value.to_coerced
#=> 29.4
value.to_coerced.class
#=> Float

Time

value = Quack("2014-03-22T03:00:00Z")
value.class
#=> Quack::Types::Time
value.to_coerced
#=> 2014-03-22T03:00:00+00:00
value.to_coerced.class
#=> Time

Boolean

value = Quack("true")
value.class
#=> Quack::Types::Boolean
value.to_coerced
#=> true
value.to_coerced.class
#=> TrueClass

value = Quack("false")
value.class
#=> Quack::Types::Boolean
value.to_coerced
#=> false
value.to_coerced.class
#=> FalseClass

Null

value = Quack(nil)
value.class
#=> Quack::Types::Null
value.to_coerced
#=> nil
value.to_coerced.class
#=> NilClass

String

value = Quack("foo")
value.class
#=> Quack::Types::String
value.to_coerced
#=> foo
value.to_coerced.class
#=> String

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request