Class: GoogleContacts::Proxies::Emails::Email

Inherits:
HashWithIndifferentAccess
  • Object
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.



82
83
84
85
86
87
88
89
# File 'lib/google_contacts/proxies/emails.rb', line 82

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



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/google_contacts/proxies/emails.rb', line 116

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



105
106
107
108
109
110
# File 'lib/google_contacts/proxies/emails.rb', line 105

def []=(key, value)
  if "#{key}" == 'address' && self[key]
    raise "Cannot modify email address"
  end
  super(key, value.to_s)
end

#dupObject



112
113
114
# File 'lib/google_contacts/proxies/emails.rb', line 112

def dup
  self.class.new(@parent, self)
end

#label=(arg) ⇒ Object



100
101
102
103
# File 'lib/google_contacts/proxies/emails.rb', line 100

def label=(arg)
  delete(:rel)
  method_missing("label=", arg)
end

#primary!Object



91
92
93
# File 'lib/google_contacts/proxies/emails.rb', line 91

def primary!
  @parent.primary! self[:address]
end

#rel=(arg) ⇒ Object



95
96
97
98
# File 'lib/google_contacts/proxies/emails.rb', line 95

def rel=(arg)
  delete(:label)
  method_missing("rel=", arg)
end