geolombia 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +5 -0
- data/geolombia.gemspec +19 -0
- data/lib/geolombia/base.rb +4 -0
- data/lib/geolombia/city.rb +38 -0
- data/lib/geolombia/fixtures/cities.csv +1102 -0
- data/lib/geolombia/fixtures/states.csv +32 -0
- data/lib/geolombia/state.rb +35 -0
- data/lib/geolombia/version.rb +3 -0
- data/lib/geolombia.rb +9 -0
- data/spec/geolombia/city_spec.rb +50 -0
- data/spec/geolombia/state_spec.rb +60 -0
- data/spec/spec_helper.rb +8 -0
- metadata +82 -0
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            91,Amazonas,-1.0197222,-71.9383333
         | 
| 2 | 
            +
            05,Antioquia,7,-75.5
         | 
| 3 | 
            +
            81,Arauca,7.0902778,-70.7616667
         | 
| 4 | 
            +
            08,Atlántico,10.75,-75
         | 
| 5 | 
            +
            13,Bolívar,9,-74.3333333
         | 
| 6 | 
            +
            15,Boyacá,5.5,-72.5
         | 
| 7 | 
            +
            17,Caldas,5.25,-75.5
         | 
| 8 | 
            +
            18,Caquetá,1,-74
         | 
| 9 | 
            +
            85,Casanare,5.5,-71.5
         | 
| 10 | 
            +
            19,Cauca,2.5,-76.8333333
         | 
| 11 | 
            +
            20,Cesar,9.3333333,-73.5
         | 
| 12 | 
            +
            27,Chocó,6,-77
         | 
| 13 | 
            +
            25,Cundinamarca,5,-74.1666667
         | 
| 14 | 
            +
            23,Córdoba,8.3333333,-75.6666667
         | 
| 15 | 
            +
            94,Guainía,2.5,-69
         | 
| 16 | 
            +
            95,Guaviare,1.6894444,-72.8202778
         | 
| 17 | 
            +
            41,Huila,2.5,-75.75
         | 
| 18 | 
            +
            44,La Guajira,11.5,-72.5
         | 
| 19 | 
            +
            47,Magdalena,10,-74.5
         | 
| 20 | 
            +
            50,Meta,3.5,-73
         | 
| 21 | 
            +
            52,Nariño,1.5,-78
         | 
| 22 | 
            +
            54,Norte de Santander,8,-73
         | 
| 23 | 
            +
            86,Putumayo,0.5,-76
         | 
| 24 | 
            +
            63,Quindío,4.5,-75.6666667
         | 
| 25 | 
            +
            66,Risaralda,5,-76
         | 
| 26 | 
            +
            88,San Andrés,12.5847222,-81.7005556
         | 
| 27 | 
            +
            68,Santander,7,-73.25
         | 
| 28 | 
            +
            70,Sucre,9,-75
         | 
| 29 | 
            +
            73,Tolima,3.75,-75.25
         | 
| 30 | 
            +
            76,Valle del Cauca,3.75,-76.5
         | 
| 31 | 
            +
            97,Vaupés,0.25,-70.75
         | 
| 32 | 
            +
            99,Vichada,5,-69.5
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            require 'csv'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Geolombia
         | 
| 4 | 
            +
              class State < Base
         | 
| 5 | 
            +
                def initialize(code, name, latitude, longitude)
         | 
| 6 | 
            +
                  @code = code
         | 
| 7 | 
            +
                  @name = name
         | 
| 8 | 
            +
                  @latitude = latitude.to_f
         | 
| 9 | 
            +
                  @longitude = longitude.to_f
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
                
         | 
| 12 | 
            +
                attr_reader :code, :name, :latitude, :longitude
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
                def self.find_by_name(some_name)
         | 
| 15 | 
            +
                  @@all.select { |state| state.name == some_name }.first
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                def self.all
         | 
| 19 | 
            +
                  @@all
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
                def cities
         | 
| 23 | 
            +
                  City.all.select { |city| city.state_name == name }
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                private
         | 
| 27 | 
            +
                
         | 
| 28 | 
            +
                def self.load_fixtures
         | 
| 29 | 
            +
                  @@all = []
         | 
| 30 | 
            +
                  CSV.foreach(File.expand_path('../fixtures/states.csv', __FILE__)) do |row|
         | 
| 31 | 
            +
                    @@all << new(*row)
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
    
        data/lib/geolombia.rb
    ADDED
    
    
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require "spec_helper"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe Geolombia::State do
         | 
| 5 | 
            +
              describe "#self.load_fixtures" do
         | 
| 6 | 
            +
                it "loads the @@all variable with all cities on the cities.csv fixture file" do
         | 
| 7 | 
            +
                  Geolombia::City.class_variable_set(:@@all, []) # Clean up so we start from scratch
         | 
| 8 | 
            +
                  Geolombia::City.all.should == []
         | 
| 9 | 
            +
                  Geolombia::City.send(:load_fixtures)
         | 
| 10 | 
            +
                  Geolombia::City.all.size.should == 1102
         | 
| 11 | 
            +
                  Geolombia::City.all.each { |state| state.should be_instance_of(Geolombia::City) }
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
              describe "#self.find_by_name" do
         | 
| 16 | 
            +
                it "returns an instance of City if found" do
         | 
| 17 | 
            +
                  Geolombia::City.find_by_name("Medellín").should be_instance_of(Geolombia::City)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                it "returns nil if not found" do
         | 
| 21 | 
            +
                  Geolombia::City.find_by_name("Nowhere").should be_nil
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
              
         | 
| 25 | 
            +
              describe "getters" do
         | 
| 26 | 
            +
                it "returns correct values" do
         | 
| 27 | 
            +
                  state = Geolombia::City.find_by_name("Medellín")
         | 
| 28 | 
            +
                  state.name.should == "Medellín"
         | 
| 29 | 
            +
                  state.code.should == "05001"
         | 
| 30 | 
            +
                  state.latitude.should == 6.2913889
         | 
| 31 | 
            +
                  state.longitude.should == -75.5361111
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
              
         | 
| 35 | 
            +
              describe "#state" do
         | 
| 36 | 
            +
                before do
         | 
| 37 | 
            +
                  @medellin = Geolombia::City.find_by_name("Medellín")
         | 
| 38 | 
            +
                  @bogota = Geolombia::City.find_by_name("Bogotá")
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
                
         | 
| 41 | 
            +
                it "returns the state this city belongs to" do
         | 
| 42 | 
            +
                  @medellin.state.name.should == "Antioquia"
         | 
| 43 | 
            +
                  @bogota.state.name.should == "Cundinamarca"
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
                
         | 
| 46 | 
            +
                it "returns an instance of State" do
         | 
| 47 | 
            +
                  @medellin.state.should be_instance_of(Geolombia::State)
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
            end
         | 
| @@ -0,0 +1,60 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require "spec_helper"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe Geolombia::State do
         | 
| 5 | 
            +
              describe "#self.load_fixtures" do
         | 
| 6 | 
            +
                it "loads the @@all variable with all states on the states.csv fixture file" do
         | 
| 7 | 
            +
                  Geolombia::State.class_variable_set(:@@all, []) # Clean up so we start from scratch
         | 
| 8 | 
            +
                  Geolombia::State.all.should == []
         | 
| 9 | 
            +
                  Geolombia::State.send(:load_fixtures)
         | 
| 10 | 
            +
                  Geolombia::State.all.size.should == 32
         | 
| 11 | 
            +
                  Geolombia::State.all.each { |state| state.should be_instance_of(Geolombia::State) }
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
              describe "#self.find_by_name" do
         | 
| 16 | 
            +
                it "returns an instance of State if found" do
         | 
| 17 | 
            +
                  Geolombia::State.find_by_name("Antioquia").should be_instance_of(Geolombia::State)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                it "returns nil if not found" do
         | 
| 21 | 
            +
                  Geolombia::State.find_by_name("Nowhere").should be_nil
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
              
         | 
| 25 | 
            +
              describe "getters" do
         | 
| 26 | 
            +
                it "should return correct values" do
         | 
| 27 | 
            +
                  state = Geolombia::State.find_by_name("Antioquia")
         | 
| 28 | 
            +
                  state.name.should == "Antioquia"
         | 
| 29 | 
            +
                  state.code.should == "05"
         | 
| 30 | 
            +
                  state.latitude.should == 7.0
         | 
| 31 | 
            +
                  state.longitude.should == -75.5
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
              
         | 
| 35 | 
            +
              describe "#cities" do
         | 
| 36 | 
            +
                before do
         | 
| 37 | 
            +
                  @antioquia = Geolombia::State.find_by_name("Antioquia")
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
                
         | 
| 40 | 
            +
                it "returns an array" do
         | 
| 41 | 
            +
                  @antioquia.cities.should be_instance_of Array
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
                
         | 
| 44 | 
            +
                it "returns the actual cities that belong to that state" do
         | 
| 45 | 
            +
                  @antioquia.cities.size.should == 125
         | 
| 46 | 
            +
                  names = @antioquia.cities.map(&:name)
         | 
| 47 | 
            +
                  names.should include("Medellín")
         | 
| 48 | 
            +
                  names.should include("Envigado")
         | 
| 49 | 
            +
                  names.should include("Bello")
         | 
| 50 | 
            +
                  names.should include("Itagüí")
         | 
| 51 | 
            +
                  names.should include("Sabaneta")
         | 
| 52 | 
            +
                  names.should include("Retiro")
         | 
| 53 | 
            +
                  names.should include("Ríonegro")
         | 
| 54 | 
            +
                  names.should include("La Ceja")
         | 
| 55 | 
            +
                  names.should include("Tarso")
         | 
| 56 | 
            +
                  names.should include("Apartadó")
         | 
| 57 | 
            +
                  names.should include("Caucasia")
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: geolombia
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Andrés Mejía
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2012-07-06 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: rspec
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ! '>='
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: '0'
         | 
| 22 | 
            +
              type: :development
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ! '>='
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: '0'
         | 
| 30 | 
            +
            description: This gem gives you a list of all cities and states in Colombia and a
         | 
| 31 | 
            +
              few methods to work with them.
         | 
| 32 | 
            +
            email:
         | 
| 33 | 
            +
            - andmej@gmail.com
         | 
| 34 | 
            +
            executables: []
         | 
| 35 | 
            +
            extensions: []
         | 
| 36 | 
            +
            extra_rdoc_files: []
         | 
| 37 | 
            +
            files:
         | 
| 38 | 
            +
            - .gitignore
         | 
| 39 | 
            +
            - Gemfile
         | 
| 40 | 
            +
            - LICENSE
         | 
| 41 | 
            +
            - README.md
         | 
| 42 | 
            +
            - Rakefile
         | 
| 43 | 
            +
            - geolombia.gemspec
         | 
| 44 | 
            +
            - lib/geolombia.rb
         | 
| 45 | 
            +
            - lib/geolombia/base.rb
         | 
| 46 | 
            +
            - lib/geolombia/city.rb
         | 
| 47 | 
            +
            - lib/geolombia/fixtures/cities.csv
         | 
| 48 | 
            +
            - lib/geolombia/fixtures/states.csv
         | 
| 49 | 
            +
            - lib/geolombia/state.rb
         | 
| 50 | 
            +
            - lib/geolombia/version.rb
         | 
| 51 | 
            +
            - spec/geolombia/city_spec.rb
         | 
| 52 | 
            +
            - spec/geolombia/state_spec.rb
         | 
| 53 | 
            +
            - spec/spec_helper.rb
         | 
| 54 | 
            +
            homepage: https://github.com/andmej/geolombia
         | 
| 55 | 
            +
            licenses: []
         | 
| 56 | 
            +
            post_install_message: 
         | 
| 57 | 
            +
            rdoc_options: []
         | 
| 58 | 
            +
            require_paths:
         | 
| 59 | 
            +
            - lib
         | 
| 60 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 61 | 
            +
              none: false
         | 
| 62 | 
            +
              requirements:
         | 
| 63 | 
            +
              - - ! '>='
         | 
| 64 | 
            +
                - !ruby/object:Gem::Version
         | 
| 65 | 
            +
                  version: '0'
         | 
| 66 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 67 | 
            +
              none: false
         | 
| 68 | 
            +
              requirements:
         | 
| 69 | 
            +
              - - ! '>='
         | 
| 70 | 
            +
                - !ruby/object:Gem::Version
         | 
| 71 | 
            +
                  version: '0'
         | 
| 72 | 
            +
            requirements: []
         | 
| 73 | 
            +
            rubyforge_project: 
         | 
| 74 | 
            +
            rubygems_version: 1.8.24
         | 
| 75 | 
            +
            signing_key: 
         | 
| 76 | 
            +
            specification_version: 3
         | 
| 77 | 
            +
            summary: This gem gives you a list of all cities and states in Colombia and a few
         | 
| 78 | 
            +
              methods to work with them.
         | 
| 79 | 
            +
            test_files:
         | 
| 80 | 
            +
            - spec/geolombia/city_spec.rb
         | 
| 81 | 
            +
            - spec/geolombia/state_spec.rb
         | 
| 82 | 
            +
            - spec/spec_helper.rb
         |