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 +4 -4
- data/bin/best-nomad-cities +1 -0
- data/lib/best_nomad_cities/city.rb +6 -15
- data/lib/best_nomad_cities/scraper.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28f376bc2469b77315b2f8967b0c0d9da0634c8f
|
4
|
+
data.tar.gz: 23745fd1f26318992635781331a000f36ea751db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85acb6e468281ecaee23fc28be48361c3f4169fc6ad33a0cb7faa58533ed8f7131f741d3909a4a474b57a259889182fa9e886a9cf67843af24a52c4ed39a8dd7
|
7
|
+
data.tar.gz: 0d167fba2e04159e05b246aa6717f6b31067e116211dbe958bfe60a4e35b5c9d547ec3698d6d34ae0a1bd472deb27629e0c4dd1139762953239f27d52b2ece88
|
data/bin/best-nomad-cities
CHANGED
@@ -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
|
-
|
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
|