Sha256: 82c42c96e79ccb4f46b96d45d87d593bd085d141155c9f29144671c5536dc500

Contents?: true

Size: 808 Bytes

Versions: 2

Compression:

Stored size: 808 Bytes

Contents

require 'csv'

module Geolombia
  class City < Base

    def initialize(code, name, state_code, state_name, latitude, longitude)
      @code = code
      @name = name
      @state_code = state_code
      @state_name = state_name
      @latitude = latitude.to_f
      @longitude = longitude.to_f
    end
    
    attr_accessor :code, :name, :state_code, :state_name, :latitude, :longitude
    
    def state
      Geolombia::State.find_by_name(@state_name)
    end

    def self.find_by_name(some_name)
      @@all.select { |city| city.name == some_name }.first
    end
    
    def self.all
      @@all
    end

    private
    
    def self.load_fixtures
      @@all = []
      CSV.foreach(File.expand_path('../fixtures/cities.csv', __FILE__)) do |row|
        @@all << new(*row)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geolombia-0.0.2 lib/geolombia/city.rb
geolombia-0.0.1 lib/geolombia/city.rb