stocker 1.3.0 → 1.3.1
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 +4 -4
- data/lib/stocker.rb +33 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f00ea506db2b41a91d8150cb70a0eef1fc9f7e80
|
4
|
+
data.tar.gz: e9e51799ae4440178ab9756c19691dc537d0b26c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c7842503ab717578627c8f263c6f385d55a0d3e1237230137d306f888face329348849356bc5c8ce7cbf56ee6e200cf9d41efc2554045cb1d645cb3b18490b
|
7
|
+
data.tar.gz: acc57516bc9d1dc91c90766ea569369a973fa5a210e3f936a29142907e998013e534b487e818dbc6628e2fc27d4e858b73cbf71baa47dfc4bc53bc79cd5c577f
|
data/lib/stocker.rb
CHANGED
@@ -5,14 +5,21 @@ require 'yaml'
|
|
5
5
|
require 'thor'
|
6
6
|
require 'titleize'
|
7
7
|
|
8
|
+
# Stocker is an app for managing an inventory of items. For example, an inventory of household items such as cleaning products, foodstuffs and how many bottles of beer you have.
|
8
9
|
# @author Brandon Pittman
|
9
10
|
module Stocker
|
11
|
+
# This is the "God" object that interacts with Thor's methods.
|
10
12
|
class Generator < Thor
|
13
|
+
# This trap is so that if you <Ctrl-C> out of "Stocker#count" your terminal won't display an error.
|
11
14
|
trap("SIGINT") { exit 0 }
|
12
15
|
|
13
16
|
desc "new ITEM TOTAL", "Add ITEM with TOTAL on hand to inventory."
|
14
17
|
option :url, :aliases => :u
|
15
18
|
option :minimum, :aliases => :m, :default => 1
|
19
|
+
# Creates a new item in the inventory
|
20
|
+
# @param item [String] The item to add to the inventory
|
21
|
+
# @param total [String] How many of the new item on hand
|
22
|
+
# @return [Hash] Returns a hash of the updated inventory and writes YAML to .stocker.yaml
|
16
23
|
def new(item, total)
|
17
24
|
data = read_file
|
18
25
|
data[item] = {'total' => total.to_i, 'min' => options[:minimum].to_i, 'url' => options[:url] || read_config['url'], 'checked' => Time.now}
|
@@ -20,6 +27,10 @@ module Stocker
|
|
20
27
|
end
|
21
28
|
|
22
29
|
desc "delete ITEM", "Delete ITEM from inventory."
|
30
|
+
# Deletes an item from the inventory.
|
31
|
+
# Stocker will attempt a "fuzzy match" of the item name.
|
32
|
+
# @param item [String] The item to delete from the inventory
|
33
|
+
# @return [Hash] Returns a hash of the updated inventory and writes YAML to .stocker.yaml
|
23
34
|
def delete(item)
|
24
35
|
data = read_file
|
25
36
|
match_name(item)
|
@@ -28,6 +39,8 @@ module Stocker
|
|
28
39
|
end
|
29
40
|
|
30
41
|
desc "check", "Check for low stock items."
|
42
|
+
# Checks the total number of items on hand against their acceptable minimum values and opens the URLs of any items running low in stock.
|
43
|
+
# @return Opens a link in default web browser if URL is set for low stock item
|
31
44
|
def check
|
32
45
|
links = []
|
33
46
|
read_file.each do |key, value|
|
@@ -42,6 +55,9 @@ module Stocker
|
|
42
55
|
end
|
43
56
|
|
44
57
|
desc "total ITEM TOTAL", "Set TOTAL of ITEM."
|
58
|
+
# Set total of existing item in Stocker's inventory
|
59
|
+
# @param item [String] item to update
|
60
|
+
# @param total [String] total on hand
|
45
61
|
def total(item, total)
|
46
62
|
data = read_file
|
47
63
|
match_name(item)
|
@@ -51,6 +67,9 @@ module Stocker
|
|
51
67
|
end
|
52
68
|
|
53
69
|
desc "url ITEM URL", "Set URL of ITEM."
|
70
|
+
# Set URL of existing item in Stocker's inventory
|
71
|
+
# @param item [String] item to update
|
72
|
+
# @param url [String] URL of item
|
54
73
|
def url(item, url)
|
55
74
|
data = read_file
|
56
75
|
match_name(item)
|
@@ -60,12 +79,17 @@ module Stocker
|
|
60
79
|
end
|
61
80
|
|
62
81
|
desc "buy ITEM", "Open link to buy ITEM"
|
82
|
+
# Open URL of item
|
83
|
+
# @param item [String] existing item in inventory
|
63
84
|
def buy(item)
|
64
85
|
match_name(item)
|
65
86
|
`open -a Safari #{read_file[@@item]["url"]}`
|
66
87
|
end
|
67
88
|
|
68
89
|
desc "min ITEM MINIMUM", "Set minimum acceptable amount for ITEM."
|
90
|
+
# Set minimum acceptable amount of existing inventory item
|
91
|
+
# @param item [String] item to update
|
92
|
+
# @param min [String] acceptable minimum amount of item to always have on hand
|
69
93
|
def min(item, min)
|
70
94
|
data = read_file
|
71
95
|
match_name(item)
|
@@ -74,6 +98,9 @@ module Stocker
|
|
74
98
|
end
|
75
99
|
|
76
100
|
desc "count", "Take an interactive inventory."
|
101
|
+
# Do a count update for all inventory items *interactively*.
|
102
|
+
# Stocker#count will loop through the inventory and ask you for the total on hand count for each item.
|
103
|
+
# When the counting is finished, Stocker will run Stocker#check and open the URLs of any low stock items.
|
77
104
|
def count
|
78
105
|
values = read_file
|
79
106
|
values.each do |key, value|
|
@@ -85,6 +112,8 @@ module Stocker
|
|
85
112
|
end
|
86
113
|
|
87
114
|
desc "csv", "Write entire inventory as CSV."
|
115
|
+
# Output a CSV dump of the entire inventory. This is useful with `awk` and `sed`.
|
116
|
+
# @return [String] CSV of entire inventory
|
88
117
|
def csv
|
89
118
|
read_file.each { |key, value| puts "#{key.titlecase},#{value['total']},#{value['min']},#{value['url']},#{value['checked']}" }
|
90
119
|
end
|
@@ -99,6 +128,7 @@ module Stocker
|
|
99
128
|
|
100
129
|
example: I have 24 beers. I want to have at least 23 on hand at all times. I have 23 bags of chips, but I only need to have one at all times. The beer's difference is only one, but the chips' is 22. So even though I have more beer, it will show up below chips in the list.
|
101
130
|
LONGDESC
|
131
|
+
# Print a list of all inventory items. Green items are well stocked. Yellow items are at minimum acceptable total. Red items are below minimum acceptable total.
|
102
132
|
def list
|
103
133
|
begin
|
104
134
|
@header = [[set_color("Item", :white), set_color("Total", :white)], [set_color("=================", :white), set_color("=====", :white)]]
|
@@ -134,6 +164,9 @@ module Stocker
|
|
134
164
|
|
135
165
|
desc "config", "Set configuration settings for stocker."
|
136
166
|
option :url, :aliases => :u, :type => :string, :required => true
|
167
|
+
# Configure Stocker's default settings
|
168
|
+
# If the --url param is not passed, no configurations will be changed.
|
169
|
+
# @param --url [String] Sets the default URL that is set for newly created inventory items
|
137
170
|
def config
|
138
171
|
settings = read_config
|
139
172
|
settings['url'] = options[:url] || 'http://amazon.com'
|