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
57 58 59 |
# File 'app/models/zone.rb', line 57 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)
51 52 53 54 55 |
# File 'app/models/zone.rb', line 51 def country_list return [] if kind == "state" return members.collect { |zone_member| zone_member.zoneable } if kind == "country" members.collect { |zone_member| zone_member.zoneable.country_list }.flatten end |
#in_zone?(address) ⇒ Boolean
alias to the new include? method
23 24 25 26 |
# File 'app/models/zone.rb', line 23 def in_zone?(address) $stderr.puts "Warning: calling deprecated method :in_zone? use :include? instead." include?(address) end |
#include?(address) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/zone.rb', line 28 def include?(address) # NOTE: This is complicated by the fact that include? for HMP is broken in Rails 2.1 (so we use awkward index method) case self.kind when "country" return members.select { |zone_member| zone_member.zoneable == address.country }.any? when "state" return members.select { |zone_member| zone_member.zoneable == address.state }.any? #members.index(address.state).respond_to?(:integer?) end members.each do |zone_member| return true if zone_member.zoneable.include?(address) end false end |
#kind ⇒ Object
attr_accessor :type
11 12 13 14 15 16 |
# File 'app/models/zone.rb', line 11 def kind return "country" unless member = self.members.last return "state" if member.zoneable_type == "State" return "zone" if member.zoneable_type == "Zone" "country" end |
#kind=(value) ⇒ Object
18 19 20 |
# File 'app/models/zone.rb', line 18 def kind=(value) # do nothing - just here to satisfy the form end |