Class: Zone
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#country_list ⇒ Object
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).
-
#in_zone?(address) ⇒ Boolean
alias to the new include? method.
- #include?(address) ⇒ Boolean
-
#kind ⇒ Object
attr_accessor :type.
- #kind=(value) ⇒ Object
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
72 73 74 |
# File 'app/models/zone.rb', line 72 def <=>(other) name <=> other.name end |
#country_list ⇒ Object
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 |
# 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 else nil end }.flatten.compact end |
#in_zone?(address) ⇒ Boolean
alias to the new include? method
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
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 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 |
#kind ⇒ Object
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 |