publicstorage 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 289fa9cafef0fbd579e585804481315f664daa8e2366d0af7e29e6e8ca36e2a8
4
- data.tar.gz: d3ae363cef7d78466aa500774273910d16eda47cd6305842279636d492bf005f
3
+ metadata.gz: c9f5251b3a20251494fcb996abc4a615d4aea13328e56930cadf9d9cc55b7b85
4
+ data.tar.gz: c6118d03fc038114cca43d836c7699a3b1992a482bda995f2138272076ee318e
5
5
  SHA512:
6
- metadata.gz: 197fd2db249b2a5022219e7f2e25ac88c4461370ef757e534e273460fe6a13f261a151e541a60a48de591c9c56380f8c1a71c190d079816cbcf0759abe27dfd4
7
- data.tar.gz: 11985f88d43d959569dcf396c92e0b17cee9347a22058f1642389f7954880cbde9d0676540356bf8005eafbdc2d3c6f3938619a5d2b7b370090362998f1b6dea
6
+ metadata.gz: f29a0afa30474641681ec49b9a3b80e3e5fcffd30b26b53ae65aaf316d78bceafb894bbc789bcc8440f95220d7e1e44f290915464ebcab658560538d3c6f794b
7
+ data.tar.gz: 193ffa5234a99e8238d8f06c3e31bdaeb6bf6fe17e3be3b5378718866a7a943982d56b70695b314a0bda23edac14b6f7f7cf209edcf8ac82a51033c0e80fa53a
@@ -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,17 +63,36 @@ 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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublicStorage
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -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.4.0
105
+ changelog_uri: https://github.com/ksylvest/publicstorage/releases/tag/v1.4.0
106
106
  documentation_uri: https://publicstorage.ksylvest.com/
107
107
  post_install_message:
108
108
  rdoc_options: []