Class: GoogleContacts::Proxies::Emails::Email
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- GoogleContacts::Proxies::Emails::Email
show all
- Defined in:
- lib/google_contacts/proxies/emails.rb
Constant Summary
collapse
- DEFAULTS =
{
:rel => "http://schemas.google.com/g/2005#home"
}.freeze
Instance Method Summary
collapse
Constructor Details
#initialize(parent, attributes = {}) ⇒ Email
Returns a new instance of Email.
80
81
82
83
84
85
86
87
|
# File 'lib/google_contacts/proxies/emails.rb', line 80
def initialize(parent, attributes = {})
super(DEFAULTS)
@parent = parent
attributes.each do |key, value|
send("#{key}=", value)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &blk) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/google_contacts/proxies/emails.rb', line 123
def method_missing(sym, *args, &blk)
if sym.to_s =~ /^(\w+)(=|\?)?$/
case $2
when "="
send(:[]=, $1, *args)
when "?"
send(:[], $1) == "true"
else
send(:[], $1)
end
else
super
end
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
112
113
114
115
116
117
|
# File 'lib/google_contacts/proxies/emails.rb', line 112
def []=(key, value)
if "#{key}" == "address" && self[key]
raise "Cannot modify email address"
end
super(key, value.to_s)
end
|
#dup ⇒ Object
119
120
121
|
# File 'lib/google_contacts/proxies/emails.rb', line 119
def dup
self.class.new(@parent, self)
end
|
#label=(arg) ⇒ Object
107
108
109
110
|
# File 'lib/google_contacts/proxies/emails.rb', line 107
def label=(arg)
delete(:rel)
method_missing("label=", arg)
end
|
#name ⇒ Object
Alias “name” to “displayName”
90
91
92
|
# File 'lib/google_contacts/proxies/emails.rb', line 90
def name
method_missing(:displayName)
end
|
#name=(v) ⇒ Object
94
95
96
|
# File 'lib/google_contacts/proxies/emails.rb', line 94
def name=(v)
method_missing(:displayName=, v)
end
|
#primary! ⇒ Object
98
99
100
|
# File 'lib/google_contacts/proxies/emails.rb', line 98
def primary!
@parent.primary! self[:address]
end
|
#rel=(arg) ⇒ Object
102
103
104
105
|
# File 'lib/google_contacts/proxies/emails.rb', line 102
def rel=(arg)
delete(:label)
method_missing("rel=", arg)
end
|