city_utc 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9e1ce9b68125ef57c5f00a5f4ff372e851d76c4
4
- data.tar.gz: 01dba33affe44d348cc00b09b7516629cd55b6e5
3
+ metadata.gz: c2343450636306b04bfae4726b8798130c95eaac
4
+ data.tar.gz: 8172d54d3305360d3a9d0d6ac50af16318853363
5
5
  SHA512:
6
- metadata.gz: 92e90ee4e18720738e8903834facd3295195f214c95352c61a1e70460d1e45bf8a8d0e1f25ee9fe583d36427477a15aa4e7ca791bddcf0c7d6873408fbb0e46b
7
- data.tar.gz: 9825559d32534fc920875ededc2ac42664a0bae23504d15aefe756b73d4933c7fb4ac3d938d29e60bd5b65394a01ced7ac7cab175a3d9516c1b4bdae4a1426f4
6
+ metadata.gz: 342d51d9e8e424cfee494bb53436d03ddcefe682d0a1fe92c9039dc8e66b921d861f31738404f531395370ab8f31b189be85ddd219fbd8f4bd4d3b2829e883c7
7
+ data.tar.gz: 69ef914f7e8f1d7f26b451b0704a120dd1803302680824382c987a6d3e9cce0d66bbf51887bd273fbf7f159caef7fe6b953bc484c3f78b2fff4098243ef5d457
@@ -4,12 +4,12 @@ module CityUTC
4
4
  # == Schema for `cities` table
5
5
  #
6
6
  # CREATE TABLE `cities` (
7
- # `id` INTEGER PRIMARY KEY AUTOINCREMENT,
8
- # `city` TEXT,
9
- # `country` TEXT,
10
- # `latitude` REAL,
11
- # `longitude` REAL,
12
- # `population` INTEGER,
7
+ # `id` INTEGER PRIMARY KEY AUTOINCREMENT,
8
+ # `city` TEXT,
9
+ # `country` TEXT,
10
+ # `latitude` REAL,
11
+ # `longitude` REAL,
12
+ # `population` INTEGER,
13
13
  # `timezone_code` INTEGER
14
14
  # );
15
15
  class City < Sequel::Model
@@ -5,7 +5,7 @@ module CityUTC
5
5
  #
6
6
  # CREATE TABLE `timezones` (
7
7
  # `timezone` TEXT,
8
- # `code` INTEGER,
8
+ # `code` INTEGER,
9
9
  # PRIMARY KEY(`code`)
10
10
  # );
11
11
  class Timezone < Sequel::Model
@@ -12,16 +12,15 @@ module CityUTC
12
12
  private_class_method :restore_database
13
13
 
14
14
  def self.restorable? # no-doc
15
- archive = File.join(__dir__, '..', 'database', 'sqlite.db.gz')
16
- database = File.join(__dir__, '..', 'database', 'sqlite.db')
15
+ path_to_archive = File.join(__dir__, '..', 'database', 'sqlite.db.gz')
16
+ path_to_database = File.join(__dir__, '..', 'database', 'sqlite.db')
17
17
 
18
- File.exist?(archive) && !File.exist?(database)
18
+ File.exist?(path_to_archive) && !File.exist?(path_to_database)
19
19
  end
20
20
  private_class_method :restorable?
21
21
 
22
22
  def self.connect_to_db # no-doc
23
- path_to_database =
24
- File.join(__dir__, '..', 'database', 'sqlite.db')
23
+ path_to_database = File.join(__dir__, '..', 'database', 'sqlite.db')
25
24
 
26
25
  Sequel.connect "sqlite://#{path_to_database}"
27
26
  end
@@ -28,8 +28,8 @@ module CityUTC
28
28
  # Presents time instance as pretty formatted string.
29
29
  #
30
30
  # @example
31
- # time # ==> 2017-01-13 12:37:34 UTC
32
- # formatted(time) # ==> "UTC: 2017-01-13 12:37:34"
31
+ # time # ==> 2017-01-13 12:37:34 UTC
32
+ # pretty_formatted(time) # ==> "UTC: 2017-01-13 12:37:34"
33
33
  #
34
34
  # @param [Time] time
35
35
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe "As database." do
4
+ describe "As database" do
5
5
  it 'it creates valid Sequel::Model relation for Cities table' do
6
6
  cities = CityUTC::City
7
7
 
@@ -12,4 +12,4 @@ describe "As database." do
12
12
  .to_a.collect(&:city)
13
13
  ).to contain_exactly "tokyo", "shanghai", "bombay"
14
14
  end
15
- end # describe "As database."
15
+ end # describe "As database"
@@ -4,7 +4,7 @@ require 'net/http'
4
4
 
5
5
  # To pass this tests launch the server!
6
6
  # TODO add rspec helper to check server state and launch up when s isn't started
7
- describe "As Web Server." do
7
+ describe "As web application" do
8
8
  context 'When client sends valid request' do
9
9
  it 'returns time' do
10
10
  uri = URI('http://127.0.0.1/time?')
@@ -43,7 +43,7 @@ describe "As Web Server." do
43
43
 
44
44
  expect(response.body).to match /UNKNOWN/
45
45
  end
46
- end # context 'valid request'
46
+ end # context 'When client sends valid request'
47
47
 
48
48
  # ----------------------------------------------------
49
49
 
@@ -59,5 +59,5 @@ describe "As Web Server." do
59
59
  expect(response.body)
60
60
  .to match /Please use get http request for 'time' api endpoint/
61
61
  end
62
- end # context 'invalid request'
63
- end # describe "As Web Server. When client sends"
62
+ end # context 'When client sends invalid request'
63
+ end # describe "As web application"
@@ -8,7 +8,7 @@ module CityUTC
8
8
  allow(Time).to receive(:now).and_return local_time
9
9
  end
10
10
 
11
- context '#by_location' do
11
+ context '#for_city' do
12
12
  it "returns +'UNKNOWN'+ when +:local_location+ unrecognized" do
13
13
  expect(described_class.for_city('there_is_no_city_with_dat_name'))
14
14
  .to be_eql "UNKNOWN"
@@ -29,11 +29,11 @@ module CityUTC
29
29
  expect(described_class.for_city('Ufa').to_s)
30
30
  .to be_eql("Ufa: 2015-04-11 15:30:50")
31
31
  end
32
- end # context '#by_location'
32
+ end # context '#for_city'
33
33
 
34
34
  # ----------------------------------------------------
35
35
 
36
- context '#formatted' do
36
+ context '#pretty_formatted' do
37
37
  it 'presents time as expected(formatted string)' do
38
38
  expect(described_class.pretty_formatted(Time.now.utc))
39
39
  .to be_eql("UTC: 2015-04-11 10:30:50")
@@ -43,6 +43,6 @@ module CityUTC
43
43
  expect(described_class.pretty_formatted(Time.now.utc, "PREFIX"))
44
44
  .to be_eql("PREFIX: 2015-04-11 10:30:50")
45
45
  end
46
- end # context '#formatted'
46
+ end # context '#pretty_formatted'
47
47
  end # describe CityUTC
48
48
  end # module CityUTC
@@ -1,17 +1,19 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
- desc 'Restores database'
4
- task :restore_database! do
5
- path_to_folder = File.join(__dir__, "..", "sources", "database")
6
- path_to_database = File.join(path_to_folder, 'sqlite.db.gz')
3
+ namespace :development do
4
+ desc 'Restores database'
5
+ task :restore_database! do
6
+ path_to_folder = File.join(__dir__, "..", "sources", "database")
7
+ path_to_database = File.join(path_to_folder, 'sqlite.db.gz')
7
8
 
8
- Kernel.system "gzip -d #{path_to_database} #{path_to_folder}"
9
- end
9
+ Kernel.system "gzip -d #{path_to_database} #{path_to_folder}"
10
+ end
10
11
 
11
- desc 'Compresses database'
12
- task :compress_database! do
13
- path_to_folder = File.join(__dir__, "..", "sources", "database")
14
- path_to_database = File.join(path_to_folder, 'sqlite.db')
12
+ desc 'Compresses database'
13
+ task :compress_database! do
14
+ path_to_folder = File.join(__dir__, "..", "sources", "database")
15
+ path_to_database = File.join(path_to_folder, 'sqlite.db')
15
16
 
16
- Kernel.system "gzip -k #{path_to_database} #{path_to_folder}"
17
- end
17
+ Kernel.system "gzip -k #{path_to_database} #{path_to_folder}"
18
+ end
19
+ end # namespace :development
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
- desc 'Launches web-server (CityUTC#WebServer)'
4
- task :launch_web_server! do
3
+ desc 'Launches web-server for CityUTC'
4
+ task :launch_city_utc_web_app! do
5
5
  settings = [
6
6
  '--max-conns 2048',
7
7
  '--address 127.0.0.1',
@@ -1,45 +1,47 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
- desc "DEVELOPMENT ONLY !!! (Requests ruby >= 2.4.0" \
4
- "Creates two csv files for later import into sqlite db. " \
5
- "Original file can been downloaded by following link: " \
6
- "http://download.maxmind.com/download/worldcities/worldcitiespop.txt.gz"
7
- # Note for csv to sqlite.db converting 'DB Browser for SQLite' was used.
8
- task :prepare_for_import_to_db do
9
- require 'csv'
10
- require 'nearest_time_zone' # TODO remove dependency with original csv database
11
- require 'timezone'
3
+ namespace :development do
4
+ desc "Note: requests ruby >= 2.4.0" \
5
+ "Creates two csv files for later import into sqlite db. " \
6
+ "Original file can been downloaded by following link: " \
7
+ "http://download.maxmind.com/download/worldcities/worldcitiespop.txt.gz"
8
+ # Note for csv to sqlite.db converting 'DB Browser for SQLite' was used.
9
+ task :prepare_for_import_to_db do
10
+ require 'csv'
11
+ require 'nearest_time_zone' # TODO remove dependency with original csv database
12
+ require 'timezone'
12
13
 
13
- origin_csv = File.join(__dir__, '..', 'tmp', 'worldcitiespop.txt')
14
- timezone_mapping = Hash.new
14
+ origin_csv = File.join(__dir__, '..', 'tmp', 'worldcitiespop.txt')
15
+ timezone_mapping = Hash.new
15
16
 
16
- zones = Timezone.names.sort_by &:to_s
17
- zones.each_with_index { |zone, index| timezone_mapping[zone] = index }
17
+ zones = Timezone.names.sort_by &:to_s
18
+ zones.each_with_index { |zone, index| timezone_mapping[zone] = index }
18
19
 
19
- list = []
20
- CSV.foreach(origin_csv, encoding: 'iso-8859-1:utf-8', headers: true,
21
- liberal_parsing: true) do |row|
20
+ list = []
21
+ CSV.foreach(origin_csv, encoding: 'iso-8859-1:utf-8', headers: true,
22
+ liberal_parsing: true) do |row|
22
23
 
23
- city_name = row.fetch("City")
24
- country = row.fetch("Country")
25
- lat = row.fetch("Latitude").to_f.round(3)
26
- lng = row.fetch("Longitude").to_f.round(3)
27
- population = row.fetch("Population").to_i
28
- timezone = NearestTimeZone.to(lat, lng)
24
+ city_name = row.fetch("City")
25
+ country = row.fetch("Country")
26
+ lat = row.fetch("Latitude").to_f.round(3)
27
+ lng = row.fetch("Longitude").to_f.round(3)
28
+ population = row.fetch("Population").to_i
29
+ timezone = NearestTimeZone.to(lat, lng)
29
30
 
30
- list << [ city_name, country, lat, lng,
31
- population, timezone_mapping[timezone] ]
32
- end
31
+ list << [ city_name, country, lat, lng,
32
+ population, timezone_mapping[timezone] ]
33
+ end
33
34
 
34
- path_to_mapping = File.join(__dir__, '..', 'tmp', 'timezones.csv')
35
- CSV.open(path_to_mapping , "wb") do |csv|
36
- csv << ["timezone", "code"]
37
- timezone_mapping.each_pair { |key, value| csv << [key, value] }
38
- end
35
+ path_to_mapping = File.join(__dir__, '..', 'tmp', 'timezones.csv')
36
+ CSV.open(path_to_mapping , "wb") do |csv|
37
+ csv << ["timezone", "code"]
38
+ timezone_mapping.each_pair { |key, value| csv << [key, value] }
39
+ end
39
40
 
40
- path_to_new_csv = File.join(__dir__, '..', 'tmp', 'cities.csv')
41
- CSV.open(path_to_new_csv, "wb") do |csv|
42
- csv << ["city", "country", "latitude", "longitude", "population", "timezone_code"]
43
- list.each { |row| csv << row }
41
+ path_to_new_csv = File.join(__dir__, '..', 'tmp', 'cities.csv')
42
+ CSV.open(path_to_new_csv, "wb") do |csv|
43
+ csv << ["city", "country", "latitude", "longitude", "population", "timezone_code"]
44
+ list.each { |row| csv << row }
45
+ end
44
46
  end
45
- end
47
+ end # namespace :development
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: city_utc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuzichev Michael
@@ -133,7 +133,7 @@ homepage: https://github.com/Medvedu/City-UTC
133
133
  licenses:
134
134
  - MIT
135
135
  metadata: {}
136
- post_install_message: Sqlite
136
+ post_install_message:
137
137
  rdoc_options: []
138
138
  require_paths:
139
139
  - sources
@@ -152,9 +152,11 @@ rubyforge_project:
152
152
  rubygems_version: 2.6.8
153
153
  signing_key:
154
154
  specification_version: 4
155
- summary: This project consist of two parts. First part includes sqlite database with
156
- two tables (see Readme.md for details) with cities, coordinates and timezones. Second
157
- part is thin (web) application for work with the database.
155
+ summary: 'This project consist of two parts First part includes sqlite database with
156
+ two tables based on worldcitiespop.csv (http://download.maxmind.com/download/):
157
+ cities(city, country, latitude, longitude, population, timezone_code) timezones(timezone,
158
+ code) Second part is sinatra (web) application for work with the database throw
159
+ Sequel ORM.'
158
160
  test_files:
159
161
  - spec/tserver/utc_time_spec.rb
160
162
  - spec/spec_helper.rb