best-nomad-cities 0.2.0 → 0.3.0

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: cc6864265f8a5103c58e46d5cfa4659a374f9e50
4
- data.tar.gz: bb2c9cf2b91567323a2919e0e4f1a46ab00b3cc8
3
+ metadata.gz: 28f376bc2469b77315b2f8967b0c0d9da0634c8f
4
+ data.tar.gz: 23745fd1f26318992635781331a000f36ea751db
5
5
  SHA512:
6
- metadata.gz: 381684ad1c18f1a99c1c63e023dc0f856f4aa5231bab50977ae1b6a8cfc4af688308a955ac18c0b739d927bd15a29aa3366bef21acc41764e94ef33dc0108e50
7
- data.tar.gz: 68b205671eb64b98e0460ca62c7d7258f9da23de5ebc9d1a683a1870b23db45d845f4175f9a699c698fb03c79174b78b11b4eadead0277a95dcc21df93048557
6
+ metadata.gz: 85acb6e468281ecaee23fc28be48361c3f4169fc6ad33a0cb7faa58533ed8f7131f741d3909a4a474b57a259889182fa9e886a9cf67843af24a52c4ed39a8dd7
7
+ data.tar.gz: 0d167fba2e04159e05b246aa6717f6b31067e116211dbe958bfe60a4e35b5c9d547ec3698d6d34ae0a1bd472deb27629e0c4dd1139762953239f27d52b2ece88
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'pry'
3
4
  require_relative '../lib/best_nomad_cities'
4
5
 
5
6
  BestNomadCities::CLI.new.call
@@ -3,21 +3,6 @@ class BestNomadCities::City
3
3
 
4
4
  @@all = []
5
5
 
6
- def self.new_from_home_page(city)
7
- attrs = {
8
- name: city.css("h2").text,
9
- country: city.css("h3").text,
10
- rank: city.css(".rank").text,
11
- cost: city.css(".bottom-right").text,
12
- internet_speed: city.css(".top-right").text,
13
- weather: "#{city.css(".metric").text} / #{city.css(".imperial").text}",
14
- link: city.css('a').attribute('href').value,
15
- tg_link: "#{city.css('a').attribute('href').value}/travel-guide"
16
- }
17
-
18
- self.new(attrs)
19
- end
20
-
21
6
  def initialize(attrs)
22
7
  @name = attrs[:name]
23
8
  @country = attrs[:country]
@@ -33,4 +18,10 @@ class BestNomadCities::City
33
18
  def self.all
34
19
  @@all
35
20
  end
21
+
22
+ def self.sort_by_cost
23
+ @@all.sort! do |a,b|
24
+ b.cost.scan(/\d/).join('').to_i <=> a.cost.scan(/\d/).join('').to_i
25
+ end
26
+ end
36
27
  end
@@ -10,7 +10,21 @@ class BestNomadCities::Scraper
10
10
 
11
11
  def make_cities
12
12
  self.get_cities.each do |city|
13
- BestNomadCities::City.new_from_home_page(city)
13
+ city_attributes(city)
14
14
  end
15
15
  end
16
+
17
+ def city_attributes(city)
18
+ attrs = {
19
+ name: city.css("h2").text,
20
+ country: city.css("h3").text,
21
+ rank: city.css(".rank").text,
22
+ cost: city.css(".bottom-right").text,
23
+ internet_speed: city.css(".top-right").text,
24
+ weather: "#{city.css(".metric").text} / #{city.css(".imperial").text}",
25
+ link: city.css('a').attribute('href').value,
26
+ tg_link: "#{city.css('a').attribute('href').value}/travel-guide"
27
+ }
28
+ BestNomadCities::City.new(attrs)
29
+ end
16
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best-nomad-cities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henno Fourie