extraspace 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/extraspace/facility.rb +41 -7
- data/lib/extraspace/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6b9f72cb5e07f8752d98b4f9a03ae259d29e434bc136a83c131355ca805303c
|
4
|
+
data.tar.gz: 42db36f6586bf84339fd09b9acacdba161886a23087932a9dd7d392bb30bd5bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaa2e29a14042f4609f6aa3e7534a7e281fa7831cfd9254b8dc57309ded56fe14063fe8ce730d11a4f569e7068617eb1ab3bfdb541689de57a21d236313e751f
|
7
|
+
data.tar.gz: 2d15bad80e64d83162ab01665752d16abc198ccc65299a815c550e9eed5f121810c120ae46a0f560dc59bf8d4a0291e0de85c3470acd3bf9d9c026d34d823754
|
data/lib/extraspace/facility.rb
CHANGED
@@ -5,16 +5,31 @@ module ExtraSpace
|
|
5
5
|
#
|
6
6
|
# e.g. https://www.extraspace.com/storage/facilities/us/alabama/auburn/3264/
|
7
7
|
class Facility
|
8
|
+
DEFAULT_EMAIL = 'info@extraspace.com'
|
9
|
+
DEFAULT_PHONE = '1-855-518-1443'
|
10
|
+
|
8
11
|
SITEMAP_URL = 'https://www.extraspace.com/facility-sitemap.xml'
|
9
12
|
|
10
13
|
# @attribute [rw] id
|
11
14
|
# @return [String]
|
12
15
|
attr_accessor :id
|
13
16
|
|
17
|
+
# @attribute [rw] url
|
18
|
+
# @return [String]
|
19
|
+
attr_accessor :url
|
20
|
+
|
14
21
|
# @attribute [rw] name
|
15
22
|
# @return [String]
|
16
23
|
attr_accessor :name
|
17
24
|
|
25
|
+
# @attribute [rw] phone
|
26
|
+
# @return [String]
|
27
|
+
attr_accessor :phone
|
28
|
+
|
29
|
+
# @attribute [rw] email
|
30
|
+
# @return [String]
|
31
|
+
attr_accessor :email
|
32
|
+
|
18
33
|
# @attribute [rw] address
|
19
34
|
# @return [Address]
|
20
35
|
attr_accessor :address
|
@@ -37,14 +52,15 @@ module ExtraSpace
|
|
37
52
|
# @return [Facility]
|
38
53
|
def self.fetch(url:)
|
39
54
|
document = Crawler.html(url:)
|
40
|
-
|
41
|
-
parse(data:)
|
55
|
+
parse(url:, document:)
|
42
56
|
end
|
43
57
|
|
44
|
-
# @param
|
58
|
+
# @param url [String]
|
59
|
+
# @param document [Nokogiri::HTML::Document]
|
45
60
|
#
|
46
61
|
# @return [Facility]
|
47
|
-
def self.parse(
|
62
|
+
def self.parse(url:, document:)
|
63
|
+
data = parse_next_data(document: document)
|
48
64
|
page_data = data.dig('props', 'pageProps', 'pageData', 'data')
|
49
65
|
store_data = page_data.dig('facilityData', 'data', 'store')
|
50
66
|
unit_classes = page_data.dig('unitClasses', 'data', 'unitClasses')
|
@@ -55,7 +71,16 @@ module ExtraSpace
|
|
55
71
|
geocode = Geocode.parse(data: store_data['geocode'])
|
56
72
|
prices = unit_classes.map { |price_data| Price.parse(data: price_data) }
|
57
73
|
|
58
|
-
new(id:, name:, address:, geocode:, prices:)
|
74
|
+
new(id:, url:, name:, address:, geocode:, prices:)
|
75
|
+
end
|
76
|
+
|
77
|
+
# @param document [Nokogiri::HTML::Document]
|
78
|
+
#
|
79
|
+
# @raise [ParseError]
|
80
|
+
#
|
81
|
+
# @return [Hash]
|
82
|
+
def self.parse_next_data(document:)
|
83
|
+
JSON.parse(document.at('#__NEXT_DATA__').text)
|
59
84
|
end
|
60
85
|
|
61
86
|
def self.crawl
|
@@ -74,15 +99,21 @@ module ExtraSpace
|
|
74
99
|
end
|
75
100
|
|
76
101
|
# @param id [String]
|
102
|
+
# @param url [String]
|
77
103
|
# @param name [String]
|
78
104
|
# @param address [Address]
|
79
105
|
# @param geocode [Geocode]
|
106
|
+
# @param phone [String]
|
107
|
+
# @param email [String]
|
80
108
|
# @param prices [Array<Price>]
|
81
|
-
def initialize(id:, name:, address:, geocode:, prices:)
|
109
|
+
def initialize(id:, url:, name:, address:, geocode:, phone: DEFAULT_PHONE, email: DEFAULT_EMAIL, prices: [])
|
82
110
|
@id = id
|
111
|
+
@url = url
|
83
112
|
@name = name
|
84
113
|
@address = address
|
85
114
|
@geocode = geocode
|
115
|
+
@phone = phone
|
116
|
+
@email = email
|
86
117
|
@prices = prices
|
87
118
|
end
|
88
119
|
|
@@ -90,8 +121,11 @@ module ExtraSpace
|
|
90
121
|
def inspect
|
91
122
|
props = [
|
92
123
|
"id=#{@id.inspect}",
|
124
|
+
"url=#{@url.inspect}",
|
93
125
|
"address=#{@address.inspect}",
|
94
126
|
"geocode=#{@geocode.inspect}",
|
127
|
+
"phone=#{@phone.inspect}",
|
128
|
+
"email=#{@email.inspect}",
|
95
129
|
"prices=#{@prices.inspect}"
|
96
130
|
]
|
97
131
|
"#<#{self.class.name} #{props.join(' ')}>"
|
@@ -99,7 +133,7 @@ module ExtraSpace
|
|
99
133
|
|
100
134
|
# @return [String]
|
101
135
|
def text
|
102
|
-
"#{@id} | #{@name} | #{@address.text} | #{@geocode.text}"
|
136
|
+
"#{@id} | #{@name} | #{@phone} | #{@email} | #{@address.text} | #{@geocode.text}"
|
103
137
|
end
|
104
138
|
end
|
105
139
|
end
|
data/lib/extraspace/version.rb
CHANGED