nsastorage 1.0.1 → 1.0.4

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: 0f13e7fb615668101d5da8a5549bb85779e59499c55d6935e9d4fd2f369a1b74
4
- data.tar.gz: c2aa0859eea895d690d3e24ea7de9a2f7673be7de4fe842f31f1f81c39c702c1
3
+ metadata.gz: 949d27c50eb31c2fd300fb0b79746ce5582239ab7b471f82e69d8c7b39b45aa6
4
+ data.tar.gz: 3614b9d81dc60f5648ba04b36b499b04f30f3eb5b6208e28718bc5369b9be3be
5
5
  SHA512:
6
- metadata.gz: 2725593f7e064e70ea041f0f031cf1a2be8e7d0f024b09e14384821391748d86d6efcf081b0d89817405c89e2d253b2da0a045f0664209c19b0bd033de05c2b4
7
- data.tar.gz: 2399ae9154b3a1ac1d8af45d3aae39425f67a060aed5679e47d57d821022525539ce4b1c79e2e8e5843d3202fc9e0cea2c11febe67d16e06a41f52eb4a882079
6
+ metadata.gz: c28896e881cbed9602776cf811f77a3c09f7e461df19f3f5bd4fa2b6f3c3022bfcf449b12e07db0739db12ca0cf7944eabb77279efc0a2db60d0e3a74a8aecad
7
+ data.tar.gz: 63217a2e77acb61b0ad432298f6c428c795e385c6a7721a2551c88aabc13db8a06b1b07a482541c8bdbc85cfa933a875d5a74efe263b91cde839bb67f1056cb0
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
  [![Yard](https://img.shields.io/badge/docs-site-blue.svg)](https://nsastorage.ksylvest.com)
7
7
  [![CircleCI](https://img.shields.io/circleci/build/github/ksylvest/nsastorage)](https://circleci.com/gh/ksylvest/nsastorage)
8
8
 
9
+ A Ruby library offering both a CLI and API for scraping [NSA Storage](https://www.nsastorage.com/) self-storage facilities and prices.
10
+
9
11
  ## Installation
10
12
 
11
13
  ```bash
@@ -49,3 +51,7 @@ end
49
51
  ```bash
50
52
  nsastorage crawl
51
53
  ```
54
+
55
+ ```bash
56
+ nsastorage crawl "https://www.nsastorage.com/storage/georgia/storage-units-norcross/1-Western-Hills-Ct-2"
57
+ ```
@@ -21,7 +21,7 @@ module NSAStorage
21
21
  command = argv.shift
22
22
 
23
23
  case command
24
- when 'crawl' then crawl
24
+ when 'crawl' then crawl(*argv)
25
25
  else
26
26
  warn("unsupported command=#{command.inspect}")
27
27
  exit(Code::ERROR)
@@ -30,8 +30,9 @@ module NSAStorage
30
30
 
31
31
  private
32
32
 
33
- def crawl
34
- Crawl.run
33
+ # @param url [String] optional
34
+ def crawl(url = nil)
35
+ Crawl.run(url:)
35
36
  exit(Code::OK)
36
37
  end
37
38
 
@@ -9,21 +9,25 @@ module NSAStorage
9
9
 
10
10
  # @param stdout [IO] optional
11
11
  # @param stderr [IO] optional
12
- # @param options [Hash] optional
13
- def initialize(stdout: $stdout, stderr: $stderr, options: {})
12
+ # @param url [String] optional
13
+ def initialize(stdout: $stdout, stderr: $stderr, url: nil)
14
14
  @stdout = stdout
15
15
  @stderr = stderr
16
- @options = options
16
+ @url = url
17
17
  end
18
18
 
19
19
  def run
20
- sitemap = Facility.sitemap
21
- @stdout.puts("count=#{sitemap.links.count}")
22
- @stdout.puts
23
-
24
- sitemap.links.each { |link| process(url: link.loc) }
20
+ if @url
21
+ process(url: @url)
22
+ else
23
+ sitemap = Facility.sitemap
24
+ @stdout.puts("count=#{sitemap.links.count}")
25
+ @stdout.puts
26
+ sitemap.links.each { |link| process(url: link.loc) }
27
+ end
25
28
  end
26
29
 
30
+ # @param url [String]
27
31
  def process(url:)
28
32
  @stdout.puts(url)
29
33
  facility = Facility.fetch(url: url)
@@ -37,7 +37,7 @@ module NSAStorage
37
37
  attr_accessor :address
38
38
 
39
39
  # @attribute [rw] geocode
40
- # @return [Geocode]
40
+ # @return [Geocode, nil]
41
41
  attr_accessor :geocode
42
42
 
43
43
  # @attribute [rw] prices
@@ -127,7 +127,7 @@ module NSAStorage
127
127
 
128
128
  # @return [String]
129
129
  def text
130
- "#{@id} | #{@name} | #{@phone} | #{@email} | #{@address.text} | #{@geocode.text}"
130
+ "#{@id} | #{@name} | #{@phone} | #{@email} | #{@address.text} | #{@geocode ? @geocode.text : 'N/A'}"
131
131
  end
132
132
  end
133
133
  end
@@ -18,8 +18,10 @@ module NSAStorage
18
18
  #
19
19
  # @return [Geocode]
20
20
  def self.parse(document:)
21
- latitude = LATITUDE_REGEX.match(document.text)[:latitude]
22
- longitude = LONGITUDE_REGEX.match(document.text)[:longitude]
21
+ latitude = LATITUDE_REGEX.match(document.text)&.[](:latitude)
22
+ longitude = LONGITUDE_REGEX.match(document.text)&.[](:longitude)
23
+
24
+ return if latitude.nil? || longitude.nil?
23
25
 
24
26
  new(latitude: Float(latitude), longitude: Float(longitude))
25
27
  end
@@ -3,7 +3,7 @@
3
3
  module NSAStorage
4
4
  # The price (id + dimensions + rate) for a facility.
5
5
  class Price
6
- ID_REGEX = %r{(?<id>\d+)/(?:rent|reserve)/}
6
+ ID_REGEX = %r{/reservation/(?<facility_id>\d+)/(?<id>\d+)}
7
7
  PRICE_SELECTOR = '[data-unit-size="small"],[data-unit-size="medium"],[data-unit-size="large"]'
8
8
 
9
9
  # @attribute [rw] id
@@ -65,12 +65,13 @@ module NSAStorage
65
65
  #
66
66
  # @return [Price]
67
67
  def self.parse(element:)
68
- link = element.at_xpath(".//a[contains(text(), 'Rent')]|//a[contains(text(), 'Reserve')]")
68
+ link = element.at_css('.cta-holder > a[href*="reservation"]')
69
69
  dimensions = Dimensions.parse(element:)
70
70
  features = Features.parse(element:)
71
71
  rates = Rates.parse(element:)
72
72
 
73
- id = link ? ID_REGEX.match(link['href'])[:id] : "#{dimensions.id}-#{features.id}"
73
+ match = ID_REGEX.match(link['href']) if link
74
+ id = match ? match[:id] : "#{dimensions.id}-#{features.id}"
74
75
 
75
76
  new(id:, dimensions:, features:, rates:)
76
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NSAStorage
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsastorage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: http
@@ -115,9 +114,9 @@ licenses:
115
114
  metadata:
116
115
  rubygems_mfa_required: 'true'
117
116
  homepage_uri: https://github.com/ksylvest/nsastorage
118
- source_code_uri: https://github.com/ksylvest/nsastorage
119
- changelog_uri: https://github.com/ksylvest/nsastorage
120
- post_install_message:
117
+ source_code_uri: https://github.com/ksylvest/nsastorage/tree/v1.0.4
118
+ changelog_uri: https://github.com/ksylvest/nsastorage/releases/tag/v1.0.4
119
+ documentation_uri: https://nsastorage.ksylvest.com/
121
120
  rdoc_options: []
122
121
  require_paths:
123
122
  - lib
@@ -132,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
131
  - !ruby/object:Gem::Version
133
132
  version: '0'
134
133
  requirements: []
135
- rubygems_version: 3.5.23
136
- signing_key:
134
+ rubygems_version: 4.0.12
137
135
  specification_version: 4
138
136
  summary: A crawler for NSAStorage.
139
137
  test_files: []