diff options
| author | cedricnjanga | 2017-11-24 12:49:34 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-11-24 12:49:34 +0100 |
| commit | 9a08dc4d028f83e43a5fba83ebf09b68f21e9d49 (patch) | |
| tree | d9b6bf281e559d2f66132e4174a5280ed0f61f2c /app/models/chouette/direction.rb | |
| parent | 4ee768d80cc5374c84ed0b06a43eb4f4bda0f825 (diff) | |
| download | chouette-core-9a08dc4d028f83e43a5fba83ebf09b68f21e9d49.tar.bz2 | |
class instance variables in Direction and ConnectionLinkType models
Diffstat (limited to 'app/models/chouette/direction.rb')
| -rw-r--r-- | app/models/chouette/direction.rb | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/app/models/chouette/direction.rb b/app/models/chouette/direction.rb index 41d703b56..13d3b87ce 100644 --- a/app/models/chouette/direction.rb +++ b/app/models/chouette/direction.rb @@ -6,22 +6,6 @@ module Chouette @numerical_code = numerical_code end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) - else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end - - super text_code, numerical_code - end - end - def to_i @numerical_code end @@ -34,28 +18,47 @@ module Chouette to_s end - @@definitions = [ - ["straight_forward", 0], - ["backward", 1], - ["clock_wise", 2], - ["counter_clock_wise", 3], - ["north", 4], - ["north_west", 5], - ["west", 6], - ["south_west", 7], - ["south", 8], - ["south_east", 9], - ["east", 10], - ["north_east", 11] - ] - cattr_reader :definitions - - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + class << self + + attr_reader :definitions + @definitions = [ + ["straight_forward", 0], + ["backward", 1], + ["clock_wise", 2], + ["counter_clock_wise", 3], + ["north", 4], + ["north_west", 5], + ["west", 6], + ["south_west", 7], + ["south", 8], + ["south_east", 9], + ["east", 10], + ["north_east", 11] + ] + @all = nil + + def new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code + else + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end + + super text_code, numerical_code + end end - end + def all + @all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end + end + + end end end
\ No newline at end of file |
