uhaul 1.0.2 → 1.0.4

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: c0f8fc116c731b1c2b29f3cd4035b24a2ad56ca0df78da62271773f531c1c58d
4
- data.tar.gz: efd5b86b8034eb9b3351fba00b0c84d4b055f953efcd9b9c7355c39d53dee495
3
+ metadata.gz: 29c3331c29dc2cd48a7e33f30e31e3c280f7256f6abea575baa11ead15711ebf
4
+ data.tar.gz: 746ec6b6ae647cbcd52d04faeaddbea6bfb89c40df97ca40dc24d6f89e5e7182
5
5
  SHA512:
6
- metadata.gz: 1a181386058777f4ab775c3a86a32665ec5f7366be1ea8b30f054c4321960594e6a45a6beaee3011f1fdfaa1dd536e476329f77c94a15319006abf11c41a5c44
7
- data.tar.gz: 0ec03ddbdd12ef8ccfa985ce44f2f8dacceef4f3f3bc595264263e855d6fd8f6fed6c38e5e8cacbe6b72b0a967b3c64f3dc0bf73255821385b74ce1a1e35e3de
6
+ metadata.gz: 2865e42eafe083ef89b66a2f85bc72629a819c732708fed264d85c17285f24e20b4ece8db391b6337ef998e54e71b65594a71b64fd67697c3738e5849d876278
7
+ data.tar.gz: 873042db4ee1d66f3c7086f80c8bac4e6789afe5e556c8c1a85c30377e9bdd948faea3c2a6101fad7314f9a95719a09abbac3d0ba3dabe301a62b4d4a3048b96
data/README.md CHANGED
@@ -49,3 +49,7 @@ end
49
49
  ```bash
50
50
  uhaul crawl
51
51
  ```
52
+
53
+ ```bash
54
+ uhaul crawl "https://www.uhaul.com/Locations/Self-Storage-near-Manchester-Township-NJ-08759/925037/"
55
+ ```
data/lib/uhaul/cli.rb CHANGED
@@ -21,7 +21,7 @@ module UHaul
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 UHaul
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: url)
35
36
  exit(Code::OK)
36
37
  end
37
38
 
@@ -52,6 +53,11 @@ module UHaul
52
53
 
53
54
  options.on('-h', '--help', 'help') { help(options) }
54
55
  options.on('-v', '--version', 'version') { version }
56
+
57
+ options.separator <<~COMMANDS
58
+ commands:
59
+ crawl [url]
60
+ COMMANDS
55
61
  end
56
62
  end
57
63
  end
data/lib/uhaul/crawl.rb CHANGED
@@ -9,19 +9,22 @@ module UHaul
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
 
27
30
  def process(url:)
data/lib/uhaul/price.rb CHANGED
@@ -22,18 +22,6 @@ module UHaul
22
22
  # @return [Rates]
23
23
  attr_accessor :rates
24
24
 
25
- # @param facility_id [Integer]
26
- #
27
- # @return [Array<Price>]
28
- def self.fetch(facility_id:)
29
- url = "https://www.uhaul.com/facility-units/#{facility_id}"
30
- data = Crawler.json(url:)['data']
31
- return [] if data['error']
32
-
33
- html = data['html']['units']
34
- Nokogiri::HTML(html).css(PRICE_SELECTOR).map { |element| parse(element:) }
35
- end
36
-
37
25
  # @param id [String]
38
26
  # @param dimensions [Dimensions]
39
27
  # @param features [Features]
@@ -56,7 +44,7 @@ module UHaul
56
44
  "#<#{self.class.name} #{props.join(' ')}>"
57
45
  end
58
46
 
59
- # @return [String] e.g. "123 | 5' × 5' (25 sqft) | $100 (street) / $90 (web)"
47
+ # @return [String] e.g. "123 | 5' × 5' (25 sqft) | $90"
60
48
  def text
61
49
  "#{@id} | #{@dimensions.text} | #{@rates.text} | #{@features.text}"
62
50
  end
data/lib/uhaul/rates.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module UHaul
4
4
  # The rates (street + web) for a facility
5
5
  class Rates
6
- RATE_REGEX = /\$(?<price>[\d\.]+) Per Month/
6
+ RATE_REGEX = /\$(?<price>[\d\.\,]+) Per Month/
7
7
 
8
8
  # @attribute [rw] rate
9
9
  # @return [Integer]
@@ -16,7 +16,7 @@ module UHaul
16
16
  #
17
17
  # @return [Rates]
18
18
  def self.parse(text:)
19
- price = Float(RATE_REGEX.match(text)[:price])
19
+ price = Float(RATE_REGEX.match(text)[:price].gsub(',', ''))
20
20
 
21
21
  new(price:)
22
22
  end
data/lib/uhaul/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UHaul
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uhaul
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre