Class: Foraneus::Converters::Boolean

Inherits:
Object
  • Object
show all
Defined in:
lib/foraneus/converters/boolean.rb

Overview

Boolean converter.

When parsing, the string ‘true’ is converted to true, otherwise false is returned.

When converting to a raw value, a true value => ‘true’, a false value => ‘false’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Boolean

Returns a new instance of Boolean.



13
14
15
# File 'lib/foraneus/converters/boolean.rb', line 13

def initialize(opts = {})
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



11
12
13
# File 'lib/foraneus/converters/boolean.rb', line 11

def opts
  @opts
end

Instance Method Details

#parse(s) ⇒ Boolean

Returns:



18
19
20
21
22
23
24
# File 'lib/foraneus/converters/boolean.rb', line 18

def parse(s)
  if s == 'true'
    true
  else
    false
  end
end

#raw(v) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/foraneus/converters/boolean.rb', line 26

def raw(v)
  if v
    'true'
  else
    'false'
  end
end