Class: Compony::ModelFields::Phone

Inherits:
Base
  • Object
show all
Defined in:
lib/compony/model_fields/phone.rb

Overview

Requires 'phonelib' gem

Instance Attribute Summary

Attributes inherited from Base

#extra_attrs, #model_class, #name, #schema_key

Instance Method Summary collapse

Methods inherited from Base

#association?, #label, #multi?, #schema_line, #simpleform_input, #simpleform_input_hidden, #transform_and_join

Constructor Details

#initializePhone

Returns a new instance of Phone.



5
6
7
8
# File 'lib/compony/model_fields/phone.rb', line 5

def initialize(...)
  fail('Please include gem "phonelib" to use the :phone field type.') unless defined?(Phonelib)
  super
end

Instance Method Details

#value_for(data, controller: nil, **_) ⇒ Object



10
11
12
# File 'lib/compony/model_fields/phone.rb', line 10

def value_for(data, controller: nil, **_)
  return transform_and_join(data.send(@name), controller:) { |el| Phonelib.parse(el).international }
end