Class: Filemaker::Model::Types::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/filemaker/model/types/email.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Email

Returns a new instance of Email.



5
6
7
8
9
# File 'lib/filemaker/model/types/email.rb', line 5

def initialize(value)
  # to_s incoming value, this can prevent similar type from
  # nesting deeply
  @value = value.nil? ? nil : value.to_s
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



27
28
29
# File 'lib/filemaker/model/types/email.rb', line 27

def ==(other)
  to_s == other.to_s
end

#to_queryObject

In FileMaker, at-sign is for wildcard query. In order to search for email, we need to escape at-sign. Note the single-quote escaping! e.g. ‘[email protected]’ will become ‘a\@host.com’



35
36
37
# File 'lib/filemaker/model/types/email.rb', line 35

def to_query
  value.gsub('@', '\@')
end

#to_sObject



23
24
25
# File 'lib/filemaker/model/types/email.rb', line 23

def to_s
  value
end

#valueObject



11
12
13
14
15
16
17
# File 'lib/filemaker/model/types/email.rb', line 11

def value
  email = @value&.strip&.split(%r{,|\(|\/|\s})
          &.reject(&:empty?)&.first&.downcase
          &.gsub(/[\uFF20\uFE6B\u0040]/, '@')

  email&.include?('@') ? email : nil
end

#value=(v) ⇒ Object



19
20
21
# File 'lib/filemaker/model/types/email.rb', line 19

def value=(v)
  self.value = v
end