Class: Foraneus::Converters::Boolean
- 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
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Boolean
constructor
A new instance of Boolean.
- #parse(s) ⇒ Boolean
- #raw(v) ⇒ Object
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
#opts ⇒ Object (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
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 |