publicstorage 1.1.0 → 1.3.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: f797ad8918b9cea8da35957e83b8bbf56ab02f1bfae95ee24a0fe1a316d1117d
4
- data.tar.gz: e2a976a36b0fc0d5edefde19c7234b778257341abc9c9507029bac2d6e31f1e3
3
+ metadata.gz: 289fa9cafef0fbd579e585804481315f664daa8e2366d0af7e29e6e8ca36e2a8
4
+ data.tar.gz: d3ae363cef7d78466aa500774273910d16eda47cd6305842279636d492bf005f
5
5
  SHA512:
6
- metadata.gz: eb338e5697de874ba118f47828d19ed3ed817cd136aac67372064fcea2dabde722c34cb39924b55e91bbbca3802b8469b7caf6a5fef5fa64abf559a2c2e38090
7
- data.tar.gz: 8ed743ff4a0a59deefe92064d62345d6deaaceb860e597583758b8e7d18eac6f0db6b12f67ef0324212882ef1fea14009501b2ab0566d139241ae4d78d60f7eb
6
+ metadata.gz: 197fd2db249b2a5022219e7f2e25ac88c4461370ef757e534e273460fe6a13f261a151e541a60a48de591c9c56380f8c1a71c190d079816cbcf0759abe27dfd4
7
+ data.tar.gz: 11985f88d43d959569dcf396c92e0b17cee9347a22058f1642389f7954880cbde9d0676540356bf8005eafbdc2d3c6f3938619a5d2b7b370090362998f1b6dea
@@ -5,6 +5,9 @@ module PublicStorage
5
5
  class Facility
6
6
  SITEMAP_URL = 'https://www.publicstorage.com/sitemap_0-product.xml'
7
7
 
8
+ DEFAULT_PHONE = '1-800-742-8048'
9
+ DEFAULT_EMAIL = 'customerservice@publicstorage.com'
10
+
8
11
  PRICE_SELECTOR = '.units-results-section .unit-list-group .unit-list-item'
9
12
  LD_SELECTOR = 'script[type="application/ld+json"]'
10
13
 
@@ -14,10 +17,22 @@ module PublicStorage
14
17
  # @return [Integer]
15
18
  attr_accessor :id
16
19
 
20
+ # @attribute [rw] url
21
+ # @return [String]
22
+ attr_accessor :url
23
+
17
24
  # @attribute [rw] name
18
25
  # @return [String]
19
26
  attr_accessor :name
20
27
 
28
+ # @attribute [rw] phone
29
+ # @return [String]
30
+ attr_accessor :phone
31
+
32
+ # @attribute [rw] email
33
+ # @return [String]
34
+ attr_accessor :email
35
+
21
36
  # @attribute [rw] address
22
37
  # @return [Address]
23
38
  attr_accessor :address
@@ -40,13 +55,13 @@ module PublicStorage
40
55
  # @return [Facility]
41
56
  def self.fetch(url:)
42
57
  document = Crawler.html(url:)
43
- parse(document:)
58
+ parse(url:, document:)
44
59
  end
45
60
 
46
61
  # @param document [NokoGiri::XML::Document]
47
62
  #
48
63
  # @return [Facility]
49
- def self.parse(document:)
64
+ def self.parse(url:, document:)
50
65
  data = parse_ld(document:)
51
66
  id = Integer(data['url'].match(ID_REGEX)[:id])
52
67
  name = data['name']
@@ -55,7 +70,7 @@ module PublicStorage
55
70
 
56
71
  prices = document.css(PRICE_SELECTOR).map { |element| Price.parse(element:) }
57
72
 
58
- new(id:, name:, address:, geocode:, prices:)
73
+ new(id:, url:, name:, address:, geocode:, prices:)
59
74
  end
60
75
 
61
76
  # @param document [NokoGiri::XML::Document]
@@ -81,23 +96,31 @@ module PublicStorage
81
96
  end
82
97
 
83
98
  # @param id [String]
99
+ # @param url [String]
84
100
  # @param name [String]
85
101
  # @param address [Address]
86
102
  # @param geocode [Geocode]
87
103
  # @param prices [Array<Price>]
88
- def initialize(id:, name:, address:, geocode:, prices:)
104
+ def initialize(id:, url:, name:, address:, geocode:, phone: DEFAULT_PHONE, email: DEFAULT_EMAIL, prices: [])
89
105
  @id = id
106
+ @url = url
90
107
  @name = name
91
108
  @address = address
92
109
  @geocode = geocode
110
+ @phone = phone
111
+ @email = email
93
112
  @prices = prices
94
113
  end
95
114
 
96
115
  # @return [String]
97
116
  def inspect
98
117
  props = [
118
+ "id=#{@id.inspect}",
119
+ "url=#{@url.inspect}",
99
120
  "address=#{@address.inspect}",
100
121
  "geocode=#{@geocode.inspect}",
122
+ "phone=#{@phone.inspect}",
123
+ "email=#{@email.inspect}",
101
124
  "prices=#{@prices.inspect}"
102
125
  ]
103
126
  "#<#{self.class.name} #{props.join(' ')}>"
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PublicStorage
4
+ # The features (e.g. climate-controlled, inside-drive-up-access, outside-drive-up-access, etc) of a price.
5
+ class Features
6
+ # @param data [Hash]
7
+ #
8
+ # @return [Features]
9
+ def self.parse(data:)
10
+ features = data['features']
11
+ new(
12
+ climate_controlled: features&.include?('climate controlled'),
13
+ drive_up_access: features&.include?('drive-up access'),
14
+ first_floor_access: features&.include?('1st floor')
15
+ )
16
+ end
17
+
18
+ # @param climate_controlled [Boolean]
19
+ # @param drive_up_access [Boolean]
20
+ # @param first_floor_access [Boolean]
21
+ def initialize(climate_controlled:, drive_up_access:, first_floor_access:)
22
+ @climate_controlled = climate_controlled
23
+ @drive_up_access = drive_up_access
24
+ @first_floor_access = first_floor_access
25
+ end
26
+
27
+ # @return [String]
28
+ def inspect
29
+ props = [
30
+ "climate_controlled=#{@climate_controlled}",
31
+ "drive_up_access=#{@drive_up_access}",
32
+ "first_floor_access=#{@first_floor_access}"
33
+ ]
34
+
35
+ "#<#{self.class.name} #{props.join(' ')}>"
36
+ end
37
+
38
+ # @return [String] e.g. "Climate Controlled + First Floor Access"
39
+ def text
40
+ amenities.join(' + ')
41
+ end
42
+
43
+ # @return [Array<String>]
44
+ def amenities
45
+ [].tap do |amenities|
46
+ amenities << 'Climate Controlled' if climate_controlled?
47
+ amenities << 'Drive-Up Access' if drive_up_access?
48
+ amenities << 'First Floor Access' if first_floor_access?
49
+ end
50
+ end
51
+
52
+ # @return [Boolean]
53
+ def climate_controlled?
54
+ @climate_controlled
55
+ end
56
+
57
+ # @return [Boolean]
58
+ def drive_up_access?
59
+ @drive_up_access
60
+ end
61
+
62
+ # @return [Boolean]
63
+ def first_floor_access?
64
+ @first_floor_access
65
+ end
66
+ end
67
+ end
@@ -13,16 +13,22 @@ module PublicStorage
13
13
  # @return [Dimensions]
14
14
  attr_accessor :dimensions
15
15
 
16
+ # @attribute [rw] features
17
+ # @return [Features]
18
+ attr_accessor :features
19
+
16
20
  # @attribute [rw] rates
17
21
  # @return [Rates]
18
22
  attr_accessor :rates
19
23
 
20
24
  # @param id [String]
21
25
  # @param dimensions [Dimensions]
26
+ # @param features [Features]
22
27
  # @param rates [Rates]
23
- def initialize(id:, dimensions:, rates:)
28
+ def initialize(id:, dimensions:, features:, rates:)
24
29
  @id = id
25
30
  @dimensions = dimensions
31
+ @features = features
26
32
  @rates = rates
27
33
  end
28
34
 
@@ -31,14 +37,15 @@ module PublicStorage
31
37
  props = [
32
38
  "id=#{@id.inspect}",
33
39
  "dimensions=#{@dimensions.inspect}",
40
+ "features=#{@features.inspect}",
34
41
  "rates=#{@rates.inspect}"
35
42
  ]
36
43
  "#<#{self.class.name} #{props.join(' ')}>"
37
44
  end
38
45
 
39
- # @return [String] e.g. "123 | 5' × 5' (25 sqft) | $100 (street) / $90 (web)"
46
+ # @return [String] e.g. "123 | 5' × 5' (25 sqft) | $100 (street) / $90 (web) | Climate Controlled"
40
47
  def text
41
- "#{@id} | #{@dimensions.text} | #{@rates.text}"
48
+ "#{@id} | #{@dimensions.text} | #{@rates.text} | #{@features.text}"
42
49
  end
43
50
 
44
51
  # @param element [Nokogiri::XML::Element]
@@ -49,10 +56,12 @@ module PublicStorage
49
56
 
50
57
  rates = Rates.parse(data:)
51
58
  dimensions = Dimensions.parse(data:)
59
+ features = Features.parse(data:)
52
60
 
53
61
  new(
54
62
  id: element.attr('data-unitid'),
55
63
  dimensions: dimensions,
64
+ features: features,
56
65
  rates: rates
57
66
  )
58
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublicStorage
4
- VERSION = '1.1.0'
4
+ VERSION = '1.3.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.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -87,6 +87,7 @@ files:
87
87
  - lib/publicstorage/crawler.rb
88
88
  - lib/publicstorage/dimensions.rb
89
89
  - lib/publicstorage/facility.rb
90
+ - lib/publicstorage/features.rb
90
91
  - lib/publicstorage/fetch_error.rb
91
92
  - lib/publicstorage/geocode.rb
92
93
  - lib/publicstorage/link.rb
@@ -100,8 +101,8 @@ licenses:
100
101
  metadata:
101
102
  rubygems_mfa_required: 'true'
102
103
  homepage_uri: https://github.com/ksylvest/publicstorage
103
- source_code_uri: https://github.com/ksylvest/publicstorage/tree/v1.1.0
104
- changelog_uri: https://github.com/ksylvest/publicstorage/releases/tag/v1.1.0
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
105
106
  documentation_uri: https://publicstorage.ksylvest.com/
106
107
  post_install_message:
107
108
  rdoc_options: []