Class: Booletania::Method
- Inherits:
-
Object
- Object
- Booletania::Method
- Defined in:
- lib/booletania/method.rb
Instance Attribute Summary collapse
-
#boolean_column_name ⇒ Object
readonly
Returns the value of attribute boolean_column_name.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #_options ⇒ Object
- #_text ⇒ Object
-
#initialize(klass, boolean_column_name) ⇒ Method
constructor
A new instance of Method.
Constructor Details
#initialize(klass, boolean_column_name) ⇒ Method
Returns a new instance of Method.
5 6 7 8 |
# File 'lib/booletania/method.rb', line 5 def initialize(klass, boolean_column_name) @klass = klass @boolean_column_name = boolean_column_name end |
Instance Attribute Details
#boolean_column_name ⇒ Object (readonly)
Returns the value of attribute boolean_column_name.
3 4 5 |
# File 'lib/booletania/method.rb', line 3 def boolean_column_name @boolean_column_name end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/booletania/method.rb', line 3 def klass @klass end |
Instance Method Details
#_options ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/booletania/method.rb', line 22 def path_keys = i18n_path_keys + [{}] <<-RUBY def #{boolean_column_name}_options I18n.t("#{path_keys[0]}", default: #{path_keys[1..-1]}).invert.map { |k, v| [k, v.to_b] } end RUBY end |
#_text ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/booletania/method.rb', line 10 def _text i18n_true_keys = i18n_keys('true') + [true.to_s.humanize] i18n_false_keys = i18n_keys('false') + [false.to_s.humanize] <<-RUBY def #{boolean_column_name}_text keys = #{boolean_column_name}? ? #{i18n_true_keys} : #{i18n_false_keys} I18n.t(keys[0], default: keys[1..-1]) end RUBY end |