Class: Booletania::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/booletania/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/booletania/method.rb', line 3

def klass
  @klass
end

Instance Method Details

#_optionsObject



22
23
24
25
26
27
28
29
# File 'lib/booletania/method.rb', line 22

def _options
  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

#_textObject



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