diff options
Diffstat (limited to 'app/models/chouette')
| -rw-r--r-- | app/models/chouette/area_type.rb | 25 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 9 |
2 files changed, 27 insertions, 7 deletions
diff --git a/app/models/chouette/area_type.rb b/app/models/chouette/area_type.rb index 4703ea646..e17d2ee8d 100644 --- a/app/models/chouette/area_type.rb +++ b/app/models/chouette/area_type.rb @@ -1,13 +1,22 @@ class Chouette::AreaType include Comparable - ALL = %i(zdep zder zdlp zdlr lda gdl).freeze + COMMERCIAL = %i(zdep zder zdlp zdlr lda gdl).freeze + NON_COMMERCIAL = %i(deposit border service_area relief other).freeze + ALL = COMMERCIAL + NON_COMMERCIAL + @@commercial = COMMERCIAL + @@non_commercial = NON_COMMERCIAL @@all = ALL - mattr_accessor :all + mattr_accessor :all, :commercial, :non_commercial - def self.all=(values) - @@all = ALL & values + def self.commercial=(values) + @@commercial = COMMERCIAL & values + reset_caches! + end + + def self.non_commercial=(values) + @@non_commercial = NON_COMMERCIAL & values reset_caches! end @@ -20,12 +29,14 @@ class Chouette::AreaType end def self.reset_caches! + @@all = @@commercial + @@non_commercial @@instances = {} - @@options = nil + @@options = {} end - def self.options - @@options ||= all.map { |c| find(c) }.map { |t| [ t.label, t.code ] } + def self.options(kind=:all) + @@options ||= {} + @@options[kind] ||= self.send(kind).map { |c| find(c) }.map { |t| [ t.label, t.code ] } end attr_reader :code diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index ea1855ea8..d270a8696 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -10,6 +10,7 @@ module Chouette extend Enumerize enumerize :area_type, in: Chouette::AreaType::ALL + enumerize :kind, in: %i(commercial non_commercial) with_options dependent: :destroy do |assoc| assoc.has_many :stop_points @@ -96,6 +97,10 @@ module Chouette end end + def local_id + id.to_s + end + def children_in_depth return [] if self.children.empty? @@ -374,5 +379,9 @@ module Chouette return nil unless time_zone.present? ActiveSupport::TimeZone[time_zone]&.formatted_offset end + + def commercial? + kind == "commercial" + end end end |
