worldfactbook 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/worldfactbook/country.rb +96 -91
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,10 +1,15 @@
1
1
  module Worldfactbook
2
+ require 'iconv'
3
+
2
4
  class Country
3
- attr_accessor :country
5
+ attr_accessor :country, :wfb_location
4
6
 
5
7
  def initialize(country)
6
8
  @country = country.downcase
7
9
  @code = CountryCode.new(@country).code
10
+ @ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
11
+ @wfb_location = "http://rubyworldfactbook.com"
12
+
8
13
  end
9
14
 
10
15
  def countries
@@ -12,19 +17,19 @@ module Worldfactbook
12
17
  end
13
18
 
14
19
  def flag
15
- doc.css('.flag_border').to_s.gsub(/\.\.\/graphics/,'http://rubyworldfactbook.com/graphics').gsub(/"/,'').scan(/http\S+/)[0]
20
+ (@ic.iconv(doc.css('.flag_border').to_s + ' ')[0..-2]).gsub(/\.\.\/graphics/,'http://rubyworldfactbook.com/graphics').gsub(/"/,'').scan(/http\S+/)[0]
16
21
  end
17
22
 
18
23
  def map_location
19
- doc.css('#region-content td tr:nth-child(2) td:nth-child(2) img:nth-child(1)').to_s.gsub(/\.\.\/graphics/,'http://rubyworldfactbook.com/graphics').gsub(/"/,'').scan(/http\S+/)[0]
24
+ (@ic.iconv(doc.css('#region-content td tr:nth-child(2) td:nth-child(2) img:nth-child(1)').to_s + ' ')[0..-2]).gsub(/\.\.\/graphics/,'http://rubyworldfactbook.com/graphics').gsub(/"/,'').scan(/http\S+/)[0]
20
25
  end
21
26
 
22
27
  def map_world
23
- return "http://rubyworldfactbook.com/graphics/maps/newmaps/#{@code}-map.gif"
28
+ return "#{@wfb_location}/graphics/maps/newmaps/#{@code}-map.gif"
24
29
  end
25
30
 
26
31
  def intro
27
- doc.css('#CollapsiblePanel1_Intro #data .category_data').text
32
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Intro #data .category_data').text + ' ')[0..-2])
28
33
  end
29
34
 
30
35
  def geography
@@ -57,65 +62,65 @@ module Worldfactbook
57
62
  ## GEOGRAPHY ##
58
63
 
59
64
  def location
60
- doc.css('#CollapsiblePanel1_Geo tr:nth-child(2) .category_data').text
65
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Geo tr:nth-child(2) .category_data').text + ' ')[0..-2])
61
66
  end
62
67
 
63
68
  def area
64
- doc.css('#CollapsiblePanel1_Geo tr:nth-child(11) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
69
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Geo tr:nth-child(11) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
65
70
  end
66
71
 
67
72
  def area_comparative
68
- doc.css('#CollapsiblePanel1_Geo tr:nth-child(14) .category_data').text
73
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Geo tr:nth-child(14) .category_data').text + ' ')[0..-2])
69
74
  end
70
75
 
71
76
  def climate
72
- doc.css('#CollapsiblePanel1_Geo tr:nth-child(26) .category_data').text
77
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Geo tr:nth-child(26) .category_data').text + ' ')[0..-2])
73
78
  end
74
79
 
75
80
  def terrain
76
- doc.css('#CollapsiblePanel1_Geo tr:nth-child(29) .category_data').text
81
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Geo tr:nth-child(29) .category_data').text + ' ')[0..-2])
77
82
  end
78
83
 
79
84
  def elevation
80
- doc.css('#CollapsiblePanel1_Geo tr:nth-child(32) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
85
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Geo tr:nth-child(32) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
81
86
  end
82
87
 
83
88
  def natural_resources
84
- doc.css('#CollapsiblePanel1_Geo tr:nth-child(35) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
89
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Geo tr:nth-child(35) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
85
90
  end
86
91
 
87
92
 
88
93
  ## PEOPLE ##
89
94
 
90
95
  def population
91
- doc.css('#CollapsiblePanel1_People tr:nth-child(2) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
96
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(2) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
92
97
  end
93
98
 
94
99
  def age_structure
95
- doc.css('#CollapsiblePanel1_People tr:nth-child(5) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
100
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(5) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
96
101
  end
97
102
 
98
103
  def median_age
99
- doc.css('#CollapsiblePanel1_People tr:nth-child(8) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
104
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(8) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
100
105
  end
101
106
 
102
107
  def population_growth
103
- doc.css('#CollapsiblePanel1_People tr:nth-child(11) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
108
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(11) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
104
109
  end
105
110
 
106
111
  def birth_rate
107
- doc.css('#CollapsiblePanel1_People tr:nth-child(14) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
112
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(14) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
108
113
  end
109
114
 
110
115
  def death_rate
111
- doc.css('#CollapsiblePanel1_People tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
116
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(17) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
112
117
  end
113
118
 
114
119
  def net_migration
115
120
  if ['xx'].include?(@code)
116
121
  return nil
117
122
  else
118
- doc.css('#CollapsiblePanel1_People tr:nth-child(20) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
123
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(20) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
119
124
  end
120
125
  end
121
126
 
@@ -123,9 +128,9 @@ module Worldfactbook
123
128
  if ['ee'].include?(@code)
124
129
  return nil
125
130
  elsif ['xx'].include?(@code)
126
- doc.css('#CollapsiblePanel1_People tr:nth-child(20) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
131
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(20) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
127
132
  else
128
- doc.css('#CollapsiblePanel1_People tr:nth-child(23) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
133
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(23) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
129
134
  end
130
135
  end
131
136
 
@@ -133,85 +138,85 @@ module Worldfactbook
133
138
  if ['ee', 'xx'].include?(@code)
134
139
  return nil
135
140
  else
136
- doc.css('#CollapsiblePanel1_People tr:nth-child(26) .category_data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
141
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(26) .category_data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
137
142
  end
138
143
  end
139
144
 
140
145
  def sex_ratio
141
146
  if ['ee', 'xx'].include?(@code)
142
- doc.css('#CollapsiblePanel1_People tr:nth-child(23) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
147
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(23) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
143
148
  else
144
- doc.css('#CollapsiblePanel1_People tr:nth-child(29) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
149
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(29) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
145
150
  end
146
151
  end
147
152
 
148
153
  def infant_mortality
149
154
  if ['ee', 'xx'].include?(@code)
150
- doc.css('#CollapsiblePanel1_People tr:nth-child(26) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
155
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(26) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
151
156
  else
152
- doc.css('#CollapsiblePanel1_People tr:nth-child(32) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
157
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(32) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
153
158
  end
154
159
  end
155
160
 
156
161
  def life_expectancy
157
162
  if ['ee', 'xx'].include?(@code)
158
- doc.css('#CollapsiblePanel1_People tr:nth-child(29) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
163
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(29) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
159
164
  else
160
- doc.css('#CollapsiblePanel1_People tr:nth-child(35) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
165
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(35) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
161
166
  end
162
167
  end
163
168
 
164
169
  def fertility_rate
165
170
  if ['ee', 'xx'].include?(@code)
166
- doc.css('#CollapsiblePanel1_People tr:nth-child(32) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
171
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(32) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
167
172
  else
168
- doc.css('#CollapsiblePanel1_People tr:nth-child(38) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
173
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(38) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
169
174
  end
170
175
  end
171
176
 
172
177
  def ethnic_groups
173
- if doc.to_s.match("Definitions and Notes: Major infectious diseases")
174
- doc.css('#CollapsiblePanel1_People tr:nth-child(62) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
178
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Major infectious diseases")
179
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(62) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
175
180
  elsif ['ee', 'xx'].include?(@code)
176
181
  return nil
177
182
  else
178
- doc.css('#CollapsiblePanel1_People tr:nth-child(59) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
183
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(59) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
179
184
  end
180
185
  end
181
186
 
182
187
  def religions
183
- if doc.to_s.match("Definitions and Notes: Major infectious diseases")
184
- doc.css('#CollapsiblePanel1_People tr:nth-child(65) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
188
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Major infectious diseases")
189
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(65) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
185
190
  elsif ['xx'].include?(@code)
186
- doc.css('#CollapsiblePanel1_People tr:nth-child(50) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
191
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(50) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
187
192
  elsif ['ee'].include?(@code)
188
- doc.css('#CollapsiblePanel1_People tr:nth-child(44) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
193
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(44) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
189
194
  else
190
- doc.css('#CollapsiblePanel1_People tr:nth-child(62) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
195
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(62) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
191
196
  end
192
197
  end
193
198
 
194
199
  def languages
195
- if doc.to_s.match("Definitions and Notes: Major infectious diseases")
196
- doc.css('#CollapsiblePanel1_People tr:nth-child(68) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
200
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Major infectious diseases")
201
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(68) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
197
202
  elsif ['xx'].include?(@code)
198
- doc.css('#CollapsiblePanel1_People tr:nth-child(53) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
203
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(53) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
199
204
  elsif ['ee'].include?(@code)
200
- doc.css('#CollapsiblePanel1_People tr:nth-child(47) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
205
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(47) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
201
206
  else
202
- doc.css('#CollapsiblePanel1_People tr:nth-child(65) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
207
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(65) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
203
208
  end
204
209
  end
205
210
 
206
211
  def literacy
207
- if doc.to_s.match("Definitions and Notes: Major infectious diseases")
208
- doc.css('#CollapsiblePanel1_People tr:nth-child(71) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
212
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Major infectious diseases")
213
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(71) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
209
214
  elsif ['xx'].include?(@code)
210
- doc.css('#CollapsiblePanel1_People tr:nth-child(56) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
215
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(56) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
211
216
  elsif ['ee'].include?(@code)
212
217
  return nil
213
218
  else
214
- doc.css('#CollapsiblePanel1_People tr:nth-child(68) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
219
+ (@ic.iconv(doc.css('#CollapsiblePanel1_People tr:nth-child(68) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
215
220
  end
216
221
  end
217
222
 
@@ -219,58 +224,58 @@ module Worldfactbook
219
224
  ## GOVERNMENT ##
220
225
 
221
226
  def government_type
222
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(5) .category_data').text
227
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(5) .category_data').text + ' ')[0..-2])
223
228
  end
224
229
 
225
230
  def capital
226
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(8) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
231
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(8) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
227
232
  end
228
233
 
229
234
  def independence
230
- if doc.to_s.match("Definitions and Notes: Dependent areas")
231
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
235
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Dependent areas")
236
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(17) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
232
237
  else
233
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(14) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
238
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(14) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
234
239
  end
235
240
  end
236
241
 
237
242
  def legal
238
- if doc.to_s.match("Definitions and Notes: Dependent areas")
239
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(26) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
243
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Dependent areas")
244
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(26) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
240
245
  else
241
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(23) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
246
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(23) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
242
247
  end
243
248
  end
244
249
 
245
250
  def executive
246
- if doc.to_s.match("Definitions and Notes: Dependent areas")
247
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(35) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
251
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Dependent areas")
252
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(35) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
248
253
  else
249
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(32) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
254
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(32) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
250
255
  end
251
256
  end
252
257
 
253
258
  def legislative
254
- if doc.to_s.match("Definitions and Notes: Dependent areas")
255
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(38) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
259
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Dependent areas")
260
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(38) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
256
261
  else
257
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(35) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
262
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(35) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
258
263
  end
259
264
  end
260
265
 
261
266
  def judicial
262
- if doc.to_s.match("Definitions and Notes: Dependent areas")
263
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(41) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
267
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Dependent areas")
268
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(41) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
264
269
  else
265
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(38) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
270
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(38) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
266
271
  end
267
272
  end
268
273
 
269
274
  def political
270
- if doc.to_s.match("Definitions and Notes: Dependent areas")
271
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(44) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
275
+ if (@ic.iconv(doc.to_s + ' ')[0..-2]).match("Definitions and Notes: Dependent areas")
276
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(44) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
272
277
  else
273
- doc.css('#CollapsiblePanel1_Govt tr:nth-child(41) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
278
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Govt tr:nth-child(41) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').strip
274
279
  end
275
280
  end
276
281
 
@@ -278,106 +283,106 @@ module Worldfactbook
278
283
  ## ECONOMY ##
279
284
 
280
285
  def economy_overview
281
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(2) .category_data').text
286
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(2) .category_data').text + ' ')[0..-2])
282
287
  end
283
288
 
284
289
  def gdp
285
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(8) .category_data').text
290
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(8) .category_data').text + ' ')[0..-2])
286
291
  end
287
292
 
288
293
  def gdp_ppp
289
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(5) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
294
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(5) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
290
295
  end
291
296
 
292
297
  def gdp_growth
293
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(11) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
298
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(11) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
294
299
  end
295
300
 
296
301
  def gdp_capita
297
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(14) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
302
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(14) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
298
303
  end
299
304
 
300
305
  def gdp_sectors
301
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(17) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
306
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(17) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
302
307
  end
303
308
 
304
309
  def labor
305
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(20) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
310
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(20) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
306
311
  end
307
312
 
308
313
  def unemployment
309
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(26) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
314
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(26) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
310
315
  end
311
316
 
312
317
  def inflation
313
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(47) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
318
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(47) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
314
319
  end
315
320
 
316
321
  def markets
317
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(65) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
322
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(65) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
318
323
  end
319
324
 
320
325
  def exports
321
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(122) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
326
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(122) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
322
327
  end
323
328
 
324
329
  def imports
325
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(131) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
330
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(131) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
326
331
  end
327
332
 
328
333
  def debt
329
- doc.css('#CollapsiblePanel1_Econ tr:nth-child(143) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
334
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Econ tr:nth-child(143) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
330
335
  end
331
336
 
332
337
  def military
333
- doc.css('#CollapsiblePanel1_Military tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
338
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Military tr:nth-child(17) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
334
339
  end
335
340
 
336
341
 
337
342
  ## COMMUNICATIONS ##
338
343
 
339
344
  def telephones
340
- doc.css('#CollapsiblePanel1_Comm tr:nth-child(2) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
345
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Comm tr:nth-child(2) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
341
346
  end
342
347
 
343
348
  def cellphones
344
- doc.css('#CollapsiblePanel1_Comm tr:nth-child(5) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
349
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Comm tr:nth-child(5) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
345
350
  end
346
351
 
347
352
  def internet_users
348
353
  if @code == 'xx'
349
- doc.css('#CollapsiblePanel1_Comm tr:nth-child(11) .category_data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
354
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Comm tr:nth-child(11) .category_data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
350
355
  elsif @code == 'ee'
351
- doc.css('#CollapsiblePanel1_Comm tr:nth-child(17) .category_data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
356
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Comm tr:nth-child(17) .category_data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
352
357
  else
353
- doc.css('#CollapsiblePanel1_Comm tr:nth-child(20) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
358
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Comm tr:nth-child(20) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
354
359
  end
355
360
  end
356
361
 
357
362
  def internet_hosts
358
- doc.css('#CollapsiblePanel1_Comm tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
363
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Comm tr:nth-child(17) #data').text + ' ')[0..-2]).squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
359
364
  end
360
365
 
361
366
 
362
367
  ## GLOBAL ISSUES ##
363
368
 
364
369
  def disputes
365
- doc.css('#CollapsiblePanel1_Issues tr:nth-child(2) .category_data').text
370
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Issues tr:nth-child(2) .category_data').text + ' ')[0..-2])
366
371
  end
367
372
 
368
373
  def refugees
369
- doc.css('#CollapsiblePanel1_Issues tr:nth-child(5) .category_data').text
374
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Issues tr:nth-child(5) .category_data').text + ' ')[0..-2])
370
375
  end
371
376
 
372
377
  def drugs
373
- doc.css('#CollapsiblePanel1_Issues tr:nth-child(8) .category_data').text
378
+ (@ic.iconv(doc.css('#CollapsiblePanel1_Issues tr:nth-child(8) .category_data').text + ' ')[0..-2])
374
379
  end
375
380
 
376
381
 
377
382
  private
378
383
 
379
384
  def doc
380
- @document ||= Nokogiri::HTML(open("http://rubyworldfactbook.com/geos/#{@code}.html"))
385
+ @document ||= Nokogiri::HTML(open("#{@wfb_location}/geos/#{@code}.html"))
381
386
  end
382
387
  end
383
388
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: worldfactbook
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sayem Islam
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-02 00:00:00 Z
13
+ date: 2011-10-08 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -154,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
155
  - - ">="
156
156
  - !ruby/object:Gem::Version
157
- hash: -2847378457398933172
157
+ hash: 135110819283686484
158
158
  segments:
159
159
  - 0
160
160
  version: "0"