publicstorage 1.3.0 → 1.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: 289fa9cafef0fbd579e585804481315f664daa8e2366d0af7e29e6e8ca36e2a8
4
- data.tar.gz: d3ae363cef7d78466aa500774273910d16eda47cd6305842279636d492bf005f
3
+ metadata.gz: 5399b08a7b641e30fdffeed141258f0bd62506fc17ec274575f79547cd8f1eec
4
+ data.tar.gz: 55362737ee7cdce12e43f0aad79627f2956e0d580e8039eacc976419b97d1ec1
5
5
  SHA512:
6
- metadata.gz: 197fd2db249b2a5022219e7f2e25ac88c4461370ef757e534e273460fe6a13f261a151e541a60a48de591c9c56380f8c1a71c190d079816cbcf0759abe27dfd4
7
- data.tar.gz: 11985f88d43d959569dcf396c92e0b17cee9347a22058f1642389f7954880cbde9d0676540356bf8005eafbdc2d3c6f3938619a5d2b7b370090362998f1b6dea
6
+ metadata.gz: 25919c59766e6fce1e3f9e6b18fdba72d73cd6ebc178057ac8d19dbd1793c43e671e531dbd346ffc68e2be6359880df07fe03fd27be73b80972c5d14eff9a439
7
+ data.tar.gz: 8f0c1b234a94c1a190c77010cb23b115f0554d0f081c147de5ee196b2350e66b5fd81f4968fe5eed56d12d4e08e9e328e27eab207ec9899ba43654f6b96c912b
@@ -51,11 +51,21 @@ module PublicStorage
51
51
  # @return [Address]
52
52
  def self.parse(data:)
53
53
  new(
54
- street: data['streetAddress'],
54
+ street: stripe_leading_or_trailing_null(data['streetAddress']),
55
55
  city: data['addressLocality'],
56
56
  state: data['addressRegion'],
57
57
  zip: data['postalCode']
58
58
  )
59
59
  end
60
+
61
+ # NOTE: this fixes a bug w/ publicstorage that currently exists where addresses have a leading / trailing null.
62
+ #
63
+ # @param value [String]
64
+ #
65
+ # @return [String]
66
+ def self.stripe_leading_or_trailing_null(value)
67
+ match = value.match(/\A(?:null)?(?<text>.*?)(?:null)?\z/)
68
+ match[:text]
69
+ end
60
70
  end
61
71
  end
@@ -8,6 +8,7 @@ module PublicStorage
8
8
  DEFAULT_PHONE = '1-800-742-8048'
9
9
  DEFAULT_EMAIL = 'customerservice@publicstorage.com'
10
10
 
11
+ NAME_SELECTOR = '.plp-page-header'
11
12
  PRICE_SELECTOR = '.units-results-section .unit-list-group .unit-list-item'
12
13
  LD_SELECTOR = 'script[type="application/ld+json"]'
13
14
 
@@ -62,22 +63,51 @@ module PublicStorage
62
63
  #
63
64
  # @return [Facility]
64
65
  def self.parse(url:, document:)
65
- data = parse_ld(document:)
66
- id = Integer(data['url'].match(ID_REGEX)[:id])
67
- name = data['name']
66
+ data = parse_ld(document: document)
67
+ id = parse_id(data: data)
68
+ name = parse_name(document: document)
68
69
  address = Address.parse(data: data['address'])
69
70
  geocode = Geocode.parse(data: data['geo'])
70
-
71
- prices = document.css(PRICE_SELECTOR).map { |element| Price.parse(element:) }
71
+ prices = parse_prices(document: document)
72
72
 
73
73
  new(id:, url:, name:, address:, geocode:, prices:)
74
74
  end
75
75
 
76
+ # @param data [Hash]
77
+ #
78
+ # @return [Integer]
79
+ def self.parse_id(data:)
80
+ Integer(data['url'].match(ID_REGEX)[:id])
81
+ end
82
+
83
+ # @param document [NokoGiri::XML::Document]
84
+ #
85
+ # @return [String]
86
+ def self.parse_name(document:)
87
+ document.at_css(NAME_SELECTOR).text.gsub(/\s+/, ' ').strip
88
+ end
89
+
90
+ # @param docunent [NokoGiri::XML::Document]
91
+ # @return Array<Price>
92
+ def self.parse_prices(document:)
93
+ document.css(PRICE_SELECTOR).map { |element| Price.parse(element:) }
94
+ end
95
+
76
96
  # @param document [NokoGiri::XML::Document]
77
97
  #
78
98
  # @return [Hash]
79
99
  def self.parse_ld(document:)
80
- JSON.parse(document.at_css(LD_SELECTOR).text).find { |entry| entry['@type'] == 'SelfStorage' }
100
+ ld_entries = []
101
+
102
+ document.css(LD_SELECTOR).each do |element|
103
+ data = JSON.parse(element.text)
104
+ case data
105
+ when Hash then ld_entries << data
106
+ when Array then ld_entries += data
107
+ end
108
+ end
109
+
110
+ ld_entries.find { |entry| entry['@type'] == 'SelfStorage' }
81
111
  end
82
112
 
83
113
  def self.crawl
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublicStorage
4
- VERSION = '1.3.0'
4
+ VERSION = '1.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publicstorage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-08 00:00:00.000000000 Z
11
+ date: 2026-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -101,8 +101,8 @@ licenses:
101
101
  metadata:
102
102
  rubygems_mfa_required: 'true'
103
103
  homepage_uri: https://github.com/ksylvest/publicstorage
104
- source_code_uri: https://github.com/ksylvest/publicstorage/tree/v1.3.0
105
- changelog_uri: https://github.com/ksylvest/publicstorage/releases/tag/v1.3.0
104
+ source_code_uri: https://github.com/ksylvest/publicstorage/tree/v1.5.0
105
+ changelog_uri: https://github.com/ksylvest/publicstorage/releases/tag/v1.5.0
106
106
  documentation_uri: https://publicstorage.ksylvest.com/
107
107
  post_install_message:
108
108
  rdoc_options: []