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 | |
| parent | 4ee768d80cc5374c84ed0b06a43eb4f4bda0f825 (diff) | |
| download | chouette-core-9a08dc4d028f83e43a5fba83ebf09b68f21e9d49.tar.bz2 | |
class instance variables in Direction and ConnectionLinkType models
| -rw-r--r-- | app/models/chouette/connection_link_type.rb | 58 | ||||
| -rw-r--r-- | app/models/chouette/direction.rb | 77 | 
2 files changed, 70 insertions, 65 deletions
| diff --git a/app/models/chouette/connection_link_type.rb b/app/models/chouette/connection_link_type.rb index ca27ed5da..ce05c3ec4 100644 --- a/app/models/chouette/connection_link_type.rb +++ b/app/models/chouette/connection_link_type.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,19 +18,37 @@ module Chouette        camelize      end -    @@definitions = [ -      ["underground", 0], -      ["mixed", 1], -      ["overground", 2] -    ] -    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 = [ +        ["underground", 0], +        ["mixed", 1], +        ["overground", 2] +      ] +      @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 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 | 
