Module: BetterRecord::ThreeState
- Defined in:
- lib/better_record/three_state.rb
Defined Under Namespace
Modules: TableDefinition
Classes: Type
Constant Summary
collapse
- ENUM =
{
Y: 'Y',
y: 'Y',
Yes: 'Y',
yes: 'Y',
T: 'Y',
t: 'Y',
True: 'Y',
true: 'Y',
true => 'Y',
N: 'N',
n: 'N',
No: 'N',
no: 'N',
F: 'N',
f: 'N',
False: 'N',
false: 'N',
false => 'N',
U: 'U',
u: 'U',
Unknown: 'U',
unknown: 'U',
}.freeze
- TITLECASE =
{
'Y' => 'Yes',
'N' => 'No',
'U' => 'Unknown',
}.freeze
Class Method Summary
collapse
Class Method Details
.convert_to_three_state(value) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/better_record/three_state.rb', line 41
def self.convert_to_three_state(value)
case value.to_s.downcase
when /^(?:y|t(rue)?$)/
'Y'
when /^(?:n|f(alse)?$)/
'N'
else
'U'
end
end
|
.titleize(category) ⇒ Object
37
38
39
|
# File 'lib/better_record/three_state.rb', line 37
def self.titleize(category)
TITLECASE[convert_to_three_state(category) || 'U']
end
|