Class: RussianPhone::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/russian_phone/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Field

Returns a new instance of Field.



7
8
9
# File 'lib/russian_phone/field.rb', line 7

def initialize(options = {})
  @options = Number.process_options(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/russian_phone/field.rb', line 5

def options
  @options
end

Instance Method Details

#demongoize(object) ⇒ Object

Get the object as it was stored in the database, and instantiate this custom class from it.



25
26
27
# File 'lib/russian_phone/field.rb', line 25

def demongoize(object)
  RussianPhone::Number.new(object, @options)
end

#evolve(object) ⇒ Object

Converts the object that was supplied to a criteria and converts it into a database friendly form.



41
42
43
44
45
46
# File 'lib/russian_phone/field.rb', line 41

def evolve(object)
  case object
    when RussianPhone::Number then object.mongoize
    else object
  end
end

#is_a?(o) ⇒ Boolean

Mongoid 8 hack

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/russian_phone/field.rb', line 49

def is_a?(o)
  return true if o == Class
  super
end

#mongoize(object) ⇒ Object

Takes any possible object and converts it to how it would be stored in the database.



31
32
33
34
35
36
37
# File 'lib/russian_phone/field.rb', line 31

def mongoize(object)
  case object
    when RussianPhone::Number then object.mongoize
    when String then RussianPhone::Number.new(object, @options).mongoize
    else object
  end
end