bill_hicks 2.1.4 → 2.2.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
  SHA1:
3
- metadata.gz: e66edb48bd0c80665df0a3fb107609d95f72149d
4
- data.tar.gz: 541ee98fc5434bc63e93e38add4130bc95625587
3
+ metadata.gz: 0a9bf35ce7df7b67c93b47936309a3641eb7f455
4
+ data.tar.gz: b12c4e7d2b36d8b4c128a884031ea40361b3bcfe
5
5
  SHA512:
6
- metadata.gz: 9c4f416756138302838aa713dab89020a7aa028b1afd5b3079b4b36a1f8653fe8a6a1c6e37cc0ee0612d0f138ec8489d3b64bef201d51d33926e8e218dbf7d40
7
- data.tar.gz: c8c00a73a230be7519f94fcdc904dbf8917e36675d282cd571889df2635601846fbe6788b3b702513a5b31894300a3fc818187d344eacf013bf10b4c96504d96
6
+ metadata.gz: f8834a97ba02ed8cf1e2f5d290523719ffa2816b62f6fc68482cfc739b277869af7580c37538fdc1e66fa09b9083aa3613c684f86925c79fb47543bf0d1f68be
7
+ data.tar.gz: 2e2428f0371992e6972603955ff1d5be212aeb90abed38580c3e74a51a08d4bc03a832b48714b501a5d352b4fe7c58ea857ae72b096bfbfd1f37fcaa0d483248
@@ -40,5 +40,22 @@ module BillHicks
40
40
  end
41
41
  end
42
42
 
43
+ def get_file(filename)
44
+ connect(@options) do |ftp|
45
+ begin
46
+ tempfile = Tempfile.new
47
+
48
+ ftp.chdir(BillHicks.config.top_level_dir)
49
+ ftp.getbinaryfile(filename, tempfile.path)
50
+
51
+ tempfile.close
52
+
53
+ tempfile
54
+ ensure
55
+ ftp.close
56
+ end
57
+ end
58
+ end
59
+
43
60
  end
44
61
  end
@@ -15,6 +15,11 @@ module BillHicks
15
15
  @options = options
16
16
  end
17
17
 
18
+ def self.get_quantity_file(options = {})
19
+ requires!(options, :username, :password)
20
+ new(options).get_quantity_file
21
+ end
22
+
18
23
  def self.quantity(chunk_size = 15, options = {}, &block)
19
24
  requires!(options, :username, :password)
20
25
  new(options).all(chunk_size, &block)
@@ -26,33 +31,49 @@ module BillHicks
26
31
  end
27
32
 
28
33
  def all(chunk_size, &block)
29
- connect(@options) do |ftp|
30
- begin
31
- tempfile = Tempfile.new
32
-
33
- ftp.chdir(BillHicks.config.top_level_dir)
34
- ftp.getbinaryfile(INVENTORY_FILENAME, tempfile.path)
35
-
36
- SmarterCSV.process(tempfile, {
37
- chunk_size: chunk_size,
38
- force_utf8: true,
39
- convert_values_to_numeric: false,
40
- key_mapping: {
41
- product: :item_identifier,
42
- qty_avail: :quantity,
43
- }
44
- }) do |chunk|
45
- chunk.each do |item|
46
- item.except!(:product)
47
- end
48
-
49
- yield(chunk)
50
- end
51
- ensure
52
- tempfile.unlink
53
- ftp.close
34
+ quantity_tempfile = get_file(INVENTORY_FILENAME)
35
+
36
+ SmarterCSV.process(quantity_tempfile.open, {
37
+ chunk_size: chunk_size,
38
+ force_utf8: true,
39
+ convert_values_to_numeric: false,
40
+ key_mapping: {
41
+ product: :item_identifier,
42
+ qty_avail: :quantity,
43
+ }
44
+ }) do |chunk|
45
+ chunk.each do |item|
46
+ item.except!(:product)
54
47
  end
48
+
49
+ yield(chunk)
55
50
  end
51
+
52
+ quantity_tempfile.unlink
53
+ end
54
+
55
+ def get_quantity_file
56
+ quantity_tempfile = get_file(INVENTORY_FILENAME)
57
+ tempfile = Tempfile.new
58
+
59
+ SmarterCSV.process(quantity_tempfile.open, {
60
+ chunk_size: 100,
61
+ force_utf8: true,
62
+ convert_values_to_numeric: false,
63
+ key_mapping: {
64
+ product: :item_identifier,
65
+ qty_avail: :quantity,
66
+ }
67
+ }) do |chunk|
68
+ chunk.each do |item|
69
+ tempfile.puts("#{item[:item_identifier]},#{item[:quantity]}")
70
+ end
71
+ end
72
+
73
+ quantity_tempfile.unlink
74
+ tempfile.close
75
+
76
+ tempfile.path
56
77
  end
57
78
 
58
79
  alias quantity all
@@ -1,3 +1,3 @@
1
1
  module BillHicks
2
- VERSION = '2.1.4'.freeze
2
+ VERSION = '2.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bill_hicks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell