Class: Zone

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/zone.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match(address) ⇒ Object



53
54
55
# File 'app/models/zone.rb', line 53

def self.match(address)
  Zone.all.select {|zone| zone.include?(address)}
end

Instance Method Details

#<=>(other) ⇒ Object



74
75
76
# File 'app/models/zone.rb', line 74

def <=>(other)
  name <=> other.name
end

#country_listObject

convenience method for returning the countries contained within a zone (different then the countries method which only returns the zones children and does not consider the grand children if the children themselves are zones)



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/zone.rb', line 59

def country_list
  members.map {|zone_member|
    case zone_member.zoneable_type
    when "Zone"
      zone_member.zoneable.country_list
    when "Country"
      zone_member.zoneable
    when "State"
      zone_member.zoneable.country
    else
      nil
    end
  }.flatten.compact.uniq
end

#in_zone?(address) ⇒ Boolean

alias to the new include? method

Returns:

  • (Boolean)


30
31
32
33
# File 'app/models/zone.rb', line 30

def in_zone?(address)
  $stderr.puts "Warning: calling deprecated method :in_zone? use :include? instead."
  include?(address)
end

#include?(address) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/zone.rb', line 35

def include?(address)
  return false unless address

  # NOTE: This is complicated by the fact that include? for HMP is broken in Rails 2.1 (so we use awkward index method)
  members.any? do |zone_member|
    case zone_member.zoneable_type
    when "Zone"
      zone_member.zoneable.include?(address)
    when "Country"
      zone_member.zoneable == address.country
    when "State"
      zone_member.zoneable == address.state
    else
      false
    end
  end
end

#kindObject

attr_accessor :type



15
16
17
18
19
20
21
22
23
# File 'app/models/zone.rb', line 15

def kind
  member = self.members.last
  case member && member.zoneable_type
  when "State"  then "state"
  when "Zone"   then "zone"
  else
    "country"
  end
end

#kind=(value) ⇒ Object



25
26
27
# File 'app/models/zone.rb', line 25

def kind=(value)
  # do nothing - just here to satisfy the form
end