extraspace 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 5a9b243e73e7e8ded7dec1cb75998fcf2b6cfc3907e9f07ec1c6a26071c10af4
4
- data.tar.gz: 9b56a1dc1d3da8e3d83a358e1554214a58270f0936167004c29063024570445f
3
+ metadata.gz: a6b9f72cb5e07f8752d98b4f9a03ae259d29e434bc136a83c131355ca805303c
4
+ data.tar.gz: 42db36f6586bf84339fd09b9acacdba161886a23087932a9dd7d392bb30bd5bd
5
5
  SHA512:
6
- metadata.gz: 44636e3f4b7229189e6a806d14bf440fb565127a952a15911e761e440364f83c2413e7167fc55b51ce145eb11f8fe4446c7f259548a5f0dca3adc25a7cb06a4d
7
- data.tar.gz: bea8280c5d3506e5358cc69ab1561419667442ca6fc2f78216400bebf60ba2be729fd282e5daee8c79b9dae7dab2f4312fc94d66ed65b5504aeaba67933ebc13
6
+ metadata.gz: eaa2e29a14042f4609f6aa3e7534a7e281fa7831cfd9254b8dc57309ded56fe14063fe8ce730d11a4f569e7068617eb1ab3bfdb541689de57a21d236313e751f
7
+ data.tar.gz: 2d15bad80e64d83162ab01665752d16abc198ccc65299a815c550e9eed5f121810c120ae46a0f560dc59bf8d4a0291e0de85c3470acd3bf9d9c026d34d823754
@@ -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
- data = JSON.parse(document.at('#__NEXT_DATA__').text)
41
- parse(data:)
55
+ parse(url:, document:)
42
56
  end
43
57
 
44
- # @param data [Hash]
58
+ # @param url [String]
59
+ # @param document [Nokogiri::HTML::Document]
45
60
  #
46
61
  # @return [Facility]
47
- def self.parse(data:)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExtraSpace
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extraspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre