Class: CastingAttrAccessor::Parser::Boolean
- Inherits:
-
Base
- Object
- Base
- CastingAttrAccessor::Parser::Boolean
show all
- Defined in:
- lib/casting_attr_accessor/parser/boolean.rb
Instance Attribute Summary
Attributes inherited from Base
#model, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #storage_var, #writers
Instance Method Details
#attribute ⇒ Object
5
6
7
|
# File 'lib/casting_attr_accessor/parser/boolean.rb', line 5
def attribute
super.to_s.gsub('?', '').to_sym
end
|
#default_value(object) ⇒ Object
9
10
11
|
# File 'lib/casting_attr_accessor/parser/boolean.rb', line 9
def default_value(object)
super(object) || false
end
|
#parse(value) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/casting_attr_accessor/parser/boolean.rb', line 17
def parse(value)
case value
when ::TrueClass, ::FalseClass
value
else
value = value.to_s.strip.downcase
%w(t true).include?(value) || value.to_i == 1
end
end
|
#readers ⇒ Object
13
14
15
|
# File 'lib/casting_attr_accessor/parser/boolean.rb', line 13
def readers
super << :"#{attribute}?"
end
|