Class: AVM::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/contact.rb

Overview

A contributor to an image

Constant Summary collapse

FIELD_MAP =
{
  :zip => :postal_code,
  :state => :state_province,
  :province => :state_province
}
HASH_FIELDS =
[ :name, :email, :telephone, :address, :city, :state, :postal_code, :country ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Contact

Returns a new instance of Contact.



14
15
16
17
# File 'lib/avm/contact.rb', line 14

def initialize(info)
  @info = Hash[info.collect { |key, value| [ FIELD_MAP[key] || key, value ] }]
  @primary = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key) ⇒ Object



19
20
21
# File 'lib/avm/contact.rb', line 19

def method_missing(key)
  @info[FIELD_MAP[key] || key]
end

Instance Attribute Details

#primaryObject

Returns the value of attribute primary.



12
13
14
# File 'lib/avm/contact.rb', line 12

def primary
  @primary
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
# File 'lib/avm/contact.rb', line 23

def <=>(other)
  return -1 if primary?
  self.name <=> other.name
end

#primary?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/avm/contact.rb', line 32

def primary?
  @primary
end

#to_creator_list_elementObject



28
29
30
# File 'lib/avm/contact.rb', line 28

def to_creator_list_element
  %{<rdf:li>#{self.name}</rdf:li>}
end

#to_hObject



36
37
38
# File 'lib/avm/contact.rb', line 36

def to_h
  Hash[HASH_FIELDS.collect { |key| [ key, send(key) ] } ]
end