ns_geo 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 378e2f07fb7e0b5aeb10879497f4302c51289ac2
4
- data.tar.gz: 7b66f07f1d3c7b2b94844b1cdd14532d66ae565c
3
+ metadata.gz: 3636b3ee4c21974d245b13cde8fa5446c74cab54
4
+ data.tar.gz: 39a51317ae161152243d13fe40c16fca8875ae56
5
5
  SHA512:
6
- metadata.gz: 0fa0bf69ef5c04850b721e6970ddd621249a5ba425b4e320b03df57ae5ce7028cceb54604aa7de0259e86e80838c6e71030a6f78c7f7060754e72f6d5743dd30
7
- data.tar.gz: aadfd47848113de4d54b2f1e4c84d14bc09194da19f571ddf82841d9f7fd59e9def7278eece413a27d35bbc7e4c4727bec5513d1b861ef1580a135aaff3aff93
6
+ metadata.gz: ec130768b9e77ea9e45f8645fb9c4d60e89c273b82fbbdf2a4fe628efda1105a764fbf5eb8c6a7a68820ce0f63880a88b7f74c80be9612698731bab2ee8ee959
7
+ data.tar.gz: dcc6e233a8d8539fc81366780d4fc100bd0a0db9fc2ed091e289c0b76452161b59d2e0188ee7c93f3ca3d39932a76711368233d5d6d9fb6d3e27b6fe108a9683
data/Rakefile CHANGED
@@ -35,3 +35,5 @@ end
35
35
 
36
36
 
37
37
  task default: :test
38
+
39
+ load 'lib/tasks/ns_geo_tasks.rake'
@@ -1,23 +1,49 @@
1
1
  module NsGeo
2
2
  class GeoLocationImporter
3
+ require 'csv'
4
+
3
5
  def self.import
4
- require 'csv'
5
- count = 0
6
+ total = get_count
7
+ t1 = Time.now
8
+ result = read_csv_file
9
+ t2 = Time.now
10
+ delta = t2 - t1
11
+ puts('GeoLocation Import Report:')
12
+ puts("Locations are imported in: #{delta} seconds.")
13
+ puts("Total records: #{total}")
14
+ puts("Saved records: #{result[:saved]}")
15
+ puts("Discarded records: #{result[:discarded]}")
16
+ end
17
+
18
+ def self.get_count
19
+ CSV.foreach(NsGeo.csv_location, :headers => true).count
20
+ end
21
+
22
+ def self.read_csv_file
23
+ result = {saved: 0, discarded: 0}
6
24
  CSV.foreach(NsGeo.csv_location, :headers => true) do |row|
7
- geo_location = NsGeo::GeoLocation.new
8
- geo_location[:ip_address] = row[0]
9
- geo_location[:country_code] = row[1]
10
- geo_location[:country] = row[2]
11
- geo_location[:city] = row[3]
12
- geo_location[:latitude] = row[4]
13
- geo_location[:longitude] = row[5]
14
- geo_location[:mystery_value] = row[6]
15
- geo_location.save
16
- count = count + 1
17
- if count % 100 == 0
18
- return
25
+ if save(row)
26
+ result[:saved] = result[:saved] + 1
27
+ else
28
+ result[:discarded] = result[:discarded] + 1
29
+ end
30
+ if result[:saved] == 1000
31
+ return result
19
32
  end
20
33
  end
34
+ result
35
+ end
36
+
37
+ def self.save(row)
38
+ geo_location = NsGeo::GeoLocation.new
39
+ geo_location[:ip_address] = row[0]
40
+ geo_location[:country_code] = row[1]
41
+ geo_location[:country] = row[2]
42
+ geo_location[:city] = row[3]
43
+ geo_location[:latitude] = row[4]
44
+ geo_location[:longitude] = row[5]
45
+ geo_location[:mystery_value] = row[6]
46
+ geo_location.save
21
47
  end
22
48
  end
23
49
  end
@@ -1,3 +1,3 @@
1
1
  module NsGeo
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,5 +1,6 @@
1
- # desc "Explaining what the task does"
2
- # task :ns_geo do
3
- # # Task goes here
4
- # end
5
- # NsGeo::GeoLocationImporter.import
1
+ namespace :ns_geo do
2
+ desc "Imports geo location data from csv file to the database"
3
+ task import_locations: :environment do
4
+ NsGeo::GeoLocationImporter.import
5
+ end
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ns_geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - EnesKorukcu
@@ -56,7 +56,7 @@ files:
56
56
  - app/models/ns_geo/geo_location.rb
57
57
  - app/services/ns_geo/geo_location_importer.rb
58
58
  - config/routes.rb
59
- - db/migrate/20170415162318_create_ns_geo_geo_locations.rb
59
+ - db/migrate/20170416102432_create_ns_geo_geo_locations.rb
60
60
  - lib/ns_geo.rb
61
61
  - lib/ns_geo/engine.rb
62
62
  - lib/ns_geo/version.rb