dweller 0.1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ module Dweller
2
+ module City
3
+ attr_reader :name, :population, :urban_population, :area
4
+
5
+ def capital?
6
+ @capital
7
+ end
8
+
9
+ private
10
+
11
+ def city_hash=(hash)
12
+ @city_hash = hash
13
+ @name = @city_hash[:name]
14
+ @population = @city_hash[:population].to_i
15
+ @urban_population = @city_hash[:urban_population].to_i
16
+ @area = @city_hash[:area].to_f
17
+ @capital = @city_hash[:capital] == "true"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,54 @@
1
+ require 'yaml'
2
+
3
+ module Dweller
4
+ module Country
5
+ def self.included(base)
6
+ base.send :extend, ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def load_country(name)
11
+ hash = YAML::load(File.read(File.expand_path(File.join(
12
+ File.dirname(__FILE__), '..', '..', 'data', "#{name}.yml"))))
13
+ country = self.new
14
+ country.send "name=", hash[:name]
15
+ country.send "international_name=", hash[:international_name]
16
+ country.send "demonym=", hash[:demonym]
17
+ country.send "female_demonym=", hash[:female_demonym]
18
+ country.send "international_demonym=", hash[:international_demonym]
19
+ @country_hash = hash
20
+ country
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :country_hash
26
+ end
27
+
28
+ attr_reader :name, :international_name, :demonym, :female_demonym,
29
+ :international_demonym
30
+
31
+ def states
32
+ country_hash[:regions].map do |state_hash|
33
+ state = DwellerState.new
34
+ state.send "state_hash=", state_hash
35
+ state
36
+ end
37
+ end
38
+
39
+ def state(acronym)
40
+ states.find {|s| s.acronym == acronym }
41
+ end
42
+
43
+ private
44
+
45
+ class DwellerState; include Dweller::State; end
46
+
47
+ def country_hash
48
+ self.class.send :country_hash
49
+ end
50
+
51
+ attr_writer :name, :international_name, :demonym, :female_demonym,
52
+ :international_demonym
53
+ end
54
+ end
@@ -0,0 +1,28 @@
1
+ module Dweller
2
+ module State
3
+ attr_reader :name, :acronym, :region
4
+
5
+ class DwellerCity; include Dweller::City; end
6
+
7
+ def cities
8
+ @state_hash[:subregions].map do |city_hash|
9
+ city = DwellerCity.new
10
+ city.send "city_hash=", city_hash
11
+ city
12
+ end
13
+ end
14
+
15
+ def city(name)
16
+ cities.find {|c| c.name == name }
17
+ end
18
+
19
+ private
20
+
21
+ def state_hash=(hash)
22
+ @state_hash = hash
23
+ @name = @state_hash[:name]
24
+ @acronym = @state_hash[:acronym]
25
+ @region = @state_hash[:region]
26
+ end
27
+ end
28
+ end
data/lib/dweller.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Dweller
2
+ autoload :Country, 'dweller/country'
3
+ autoload :State, 'dweller/state'
4
+ autoload :City, 'dweller/city'
5
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Dweller
2
+ VERSION = '0.1.0.alpha'
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dweller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Manhães
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spreadsheet
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
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'Information about places: countries, states, cities etc.'
63
+ email: rmanhaes@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - lib/version.rb
69
+ - lib/dweller.rb
70
+ - lib/dweller/state.rb
71
+ - lib/dweller/country.rb
72
+ - lib/dweller/city.rb
73
+ - data/brazil.yml
74
+ - README.rdoc
75
+ - LICENSE.txt
76
+ homepage: https://github.com/rodrigomanhaes/dweller
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.23
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: ! 'Information about places: countries, states, cities etc.'
101
+ test_files: []