Class: ActiveRecord::Bixformer::Attribute::Booletania

Inherits:
Base
  • Object
show all
Defined in:
lib/activerecord-bixformer/attribute/booletania.rb

Instance Attribute Summary

Attributes inherited from Base

#model, #name, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #should_be_included

Constructor Details

This class inherits a constructor from ActiveRecord::Bixformer::Attribute::Base

Instance Method Details

#export(record) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/activerecord-bixformer/attribute/booletania.rb', line 5

def export(record)
  record_attribute_value = record_attribute_value(record)

  @model.activerecord_constant.__send__("#{@name}_options").find do |text, bool|
    bool == record_attribute_value
  end&.first
end

#import(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/activerecord-bixformer/attribute/booletania.rb', line 13

def import(value)
  return nil if value.blank?

  value      = value.strip
  boolean_of = @model.activerecord_constant.__send__("#{@name}_options").to_h

  return boolean_of[value] if boolean_of.key?(value)

  raise ::ActiveRecord::Bixformer::AttributeError.new(self, value) if @options[:raise]
end