Class: TypedAttributes::Parser::BooleanType
- Inherits:
-
BaseType
- Object
- BaseType
- TypedAttributes::Parser::BooleanType
show all
- Defined in:
- lib/typed_attributes/parser/boolean_type.rb
Instance Attribute Summary
Attributes inherited from BaseType
#model, #options
Instance Method Summary
collapse
Methods inherited from BaseType
#initialize, #storage_var, #writers
Instance Method Details
#attribute ⇒ Object
5
6
7
|
# File 'lib/typed_attributes/parser/boolean_type.rb', line 5
def attribute
super.to_s.gsub('?', '').to_sym
end
|
#parse(value) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/typed_attributes/parser/boolean_type.rb', line 13
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
9
10
11
|
# File 'lib/typed_attributes/parser/boolean_type.rb', line 9
def readers
super << :"#{attribute}?"
end
|