geolombia 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geolombia.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Andrés Mejía
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Geolombia
2
+
3
+ Geolombia is a gem that has a list of all cities and states in Colombia.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'geolombia'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install geolombia
18
+
19
+ ## Documentation
20
+
21
+ This README is all the documentation I've written so far.
22
+
23
+ ## Usage
24
+
25
+ Geolombia::State.find_by_name("Antioquia")
26
+ # => #<Geolombia::State:0x00000100841240 @code="05", @name="Antioquia", @latitude=7.0, @longitude=-75.5>
27
+
28
+ Geolombia::State.find_by_name("Antioquia").cities
29
+ # => Array of the 125 cities in Antioquia
30
+
31
+ Geolombia::State.all
32
+ # => Array of the 32 states in Colombia
33
+
34
+ Geolombia::City.find_by_name("Medellín")
35
+ # => #<Geolombia::City:0x00000100a601e8 @code="05001", @name="Medellín", @state_code="05", @state_name="Antioquia", @latitude=6.2913889, @longitude=-75.5361111>
36
+
37
+ Geolombia::City.find_by_name("Medellín").state
38
+ # => #<Geolombia::State:0x00000100842c80 @code="05", @name="Antioquia", @latitude=7.0, @longitude=-75.5>
39
+
40
+ Geolombia::City.all
41
+ # => Array of the 1102 cities in Colombia
42
+
43
+ ## Future Usage
44
+
45
+ Geolombia::City.where(:name => "Medellín").first
46
+
47
+ Geolombia::State.where(:name => "Antioquia").first.cities
48
+
49
+ Geolombia::City.first.state
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new('spec')
data/geolombia.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/geolombia/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrés Mejía"]
6
+ gem.email = ["andmej@gmail.com"]
7
+ gem.description = %q{This gem gives you a list of all cities and states in Colombia and a few methods to work with them.}
8
+ gem.summary = %q{This gem gives you a list of all cities and states in Colombia and a few methods to work with them.}
9
+ gem.homepage = "https://github.com/andmej/geolombia"
10
+
11
+ gem.add_development_dependency "rspec"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "geolombia"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Geolombia::VERSION
19
+ end
@@ -0,0 +1,4 @@
1
+ module Geolombia
2
+ class Base
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ require 'csv'
2
+
3
+ module Geolombia
4
+ class City < Base
5
+
6
+ def initialize(code, name, state_code, state_name, latitude, longitude)
7
+ @code = code
8
+ @name = name
9
+ @state_code = state_code
10
+ @state_name = state_name
11
+ @latitude = latitude.to_f
12
+ @longitude = longitude.to_f
13
+ end
14
+
15
+ attr_accessor :code, :name, :state_code, :state_name, :latitude, :longitude
16
+
17
+ def state
18
+ Geolombia::State.find_by_name(@state_name)
19
+ end
20
+
21
+ def self.find_by_name(some_name)
22
+ @@all.select { |city| city.name == some_name }.first
23
+ end
24
+
25
+ def self.all
26
+ @@all
27
+ end
28
+
29
+ private
30
+
31
+ def self.load_fixtures
32
+ @@all = []
33
+ CSV.foreach(File.expand_path('../fixtures/cities.csv', __FILE__)) do |row|
34
+ @@all << new(*row)
35
+ end
36
+ end
37
+ end
38
+ end