Class: View::Boolean

Inherits:
Formatter show all
Defined in:
lib/view/formatters/boolean.rb

Overview

The default formatter for booleans.

It will display "Yes" or "No".

You can configure it with I18n. When writing 'true' and 'false' as keys in yaml, please don't forget the quotes.

Examples:

config/locales/en.yml

en:
  view:
    booleans:
      'true': Yup
      'false': Nope

Instance Attribute Summary

Attributes inherited from Formatter

#block, #template, #value

Instance Method Summary (collapse)

Methods inherited from Formatter

#all_options, as, #format!, inherited, #options, skip_blank_formatter, #to_s, type

Instance Method Details

- (Object) boolean_value



29
30
31
# File 'lib/view/formatters/boolean.rb', line 29

def boolean_value
  !!value
end

- (Object) default



25
26
27
# File 'lib/view/formatters/boolean.rb', line 25

def default
  boolean_value ? "Yes" : "No"
end

- (Object) format



21
22
23
# File 'lib/view/formatters/boolean.rb', line 21

def format
  ::I18n.t(boolean_value.to_s, :scope => [:view, :booleans], :default => default)
end