GUI-graticule 0.2.7.3 → 0.2.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/graticule/location.rb +39 -0
- metadata +1 -1
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ Hoe.new("graticule", Graticule::Version::STRING) do |p|
|
|
14
14
|
p.need_zip = true
|
15
15
|
p.test_globs = ['test/**/*_test.rb']
|
16
16
|
p.changes = p.paragraphs_of('CHANGELOG.txt', 0..1).join("\n\n")
|
17
|
-
p.extra_deps << ['activesupport']
|
17
|
+
p.extra_deps << ['activesupport', 'english', 'fastercsv']
|
18
18
|
end
|
19
19
|
|
20
20
|
|
@@ -83,4 +83,4 @@ def update_placeholders!(config, thing)
|
|
83
83
|
config.each do |option, value|
|
84
84
|
thing.gsub!(":#{option}", value) if value.is_a?(String)
|
85
85
|
end
|
86
|
-
end
|
86
|
+
end
|
data/lib/graticule/location.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "fastercsv"
|
2
|
+
|
1
3
|
module Graticule
|
2
4
|
|
3
5
|
# A geographic location
|
@@ -94,6 +96,43 @@ module Graticule
|
|
94
96
|
result
|
95
97
|
end
|
96
98
|
|
99
|
+
def to_hash(options = {})
|
100
|
+
hash = ActiveSupport::OrderedHash.new
|
101
|
+
hash[:latitude] = latitude
|
102
|
+
hash[:longitude] = longitude
|
103
|
+
hash[:premise] = premise
|
104
|
+
hash[:street] = street
|
105
|
+
hash[:locality] = locality
|
106
|
+
hash[:region] = region
|
107
|
+
hash[:postal_code] = postal_code
|
108
|
+
hash[:country] = country
|
109
|
+
hash[:precision] = precision.order
|
110
|
+
hash[:warning] = warning
|
111
|
+
|
112
|
+
hash
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_xml(options = {})
|
116
|
+
options.reverse_merge!(:root => "location")
|
117
|
+
to_hash.to_xml(options)
|
118
|
+
end
|
119
|
+
|
120
|
+
def to_json(options = {})
|
121
|
+
to_hash.to_json(options)
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_csv(options = {})
|
125
|
+
hash = to_hash
|
126
|
+
|
127
|
+
FasterCSV.generate do |csv|
|
128
|
+
if(options[:headers])
|
129
|
+
csv << hash.keys
|
130
|
+
end
|
131
|
+
|
132
|
+
csv << hash.values
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
97
136
|
private
|
98
137
|
|
99
138
|
# A list of standard USPS street abbreviations. Taken from:
|