Class: Halation::Coerce

Inherits:
Object
  • Object
show all
Defined in:
lib/halation/coerce.rb

Overview

A collection of methods to coerce values into a desired type.

Class Method Summary collapse

Class Method Details

.boolean(value) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/halation/coerce.rb', line 16

def self.boolean(value)
  !!value
end

.date(value) ⇒ Date?

Returns:

  • (Date, nil)


21
22
23
# File 'lib/halation/coerce.rb', line 21

def self.date(value)
  value && Time.parse(value)
end

.integer(value) ⇒ Integer?

Returns:

  • (Integer, nil)


11
12
13
# File 'lib/halation/coerce.rb', line 11

def self.integer(value)
  value && value.to_i
end

.string(value) ⇒ String?

Returns:

  • (String, nil)


6
7
8
# File 'lib/halation/coerce.rb', line 6

def self.string(value)
  value && value.to_s
end