contacts_client 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,12 @@ class DateAttribute < ContactAttribute
17
17
  self.class.name
18
18
  end
19
19
 
20
+ # Is this a birthday with year?
21
+ # @return [Boolean]
22
+ def is_a_complete_birthday?
23
+ self.category == 'birth_day' && !self.year.blank? && self.year!='-'
24
+ end
25
+
20
26
  private
21
27
 
22
28
  def set_value
@@ -30,4 +36,4 @@ class DateAttribute < ContactAttribute
30
36
  errors.add(nil)
31
37
  end
32
38
  end
33
- end
39
+ end
@@ -115,6 +115,18 @@ class PadmaContact < LogicalModel
115
115
  local_statuses.select{|s|s['value']=='prospect'}.map{|s|s['account_name']}
116
116
  end
117
117
 
118
+ # Returns age in years of the contact or nil if age not available
119
+ # @return [Integer/NilClass]
120
+ def age
121
+ birthday = self.date_attributes.select{|da| da.is_a_complete_birthday?}[0]
122
+ now = Time.now.utc.to_date
123
+ if birthday
124
+ now.year - birthday.year.to_i - ((now.month > birthday.month.to_i || (now.month == birthday.month.to_i && now.day >= birthday.day.to_i)) ? 0 : 1)
125
+ else
126
+ nil
127
+ end
128
+ end
129
+
118
130
  def check_duplicates
119
131
  @check_duplicates || false
120
132
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dwayne Macgowan
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2013-01-08 00:00:00 -03:00
17
+ date: 2013-01-09 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency