Class: EasySettings::Coercion
- Inherits:
-
Object
- Object
- EasySettings::Coercion
- Defined in:
- lib/easy-settings/coercion.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value) ⇒ Coercion
constructor
A new instance of Coercion.
- #run ⇒ Object
Constructor Details
#initialize(value) ⇒ Coercion
Returns a new instance of Coercion.
6 7 8 |
# File 'lib/easy-settings/coercion.rb', line 6 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/easy-settings/coercion.rb', line 4 def value @value end |
Instance Method Details
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/easy-settings/coercion.rb', line 10 def run case value when "false" false when "true" true when /^json:/ JSON.parse(value.gsub(/^json:/, "")) when /^\+/ # don't treat +41791234567 as a number value else Integer(value) rescue Float(value) rescue value end end |