stocker 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stocker.rb +33 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cad3c6130530b2dccbfcd4a5465692e46cd07cc
4
- data.tar.gz: 7ff0c78354f8224e77d214849c836d9abd348d37
3
+ metadata.gz: f00ea506db2b41a91d8150cb70a0eef1fc9f7e80
4
+ data.tar.gz: e9e51799ae4440178ab9756c19691dc537d0b26c
5
5
  SHA512:
6
- metadata.gz: 12997945db1f731e29c3792fe7f15a154bcb80b61a14660d3f82db73cfcd568e76c47f671f07e5e008e0cca0e32e44d865a1fe714f1f853390dda16fdd71f611
7
- data.tar.gz: b74609f35482b4a732c2939c9a16af53de99677aeb5e648cdb592f4a1ebd7253413aa30f75b3e936f3bbf6cab6c47454237eaf79b1b8c44038bf845e80a93b70
6
+ metadata.gz: 29c7842503ab717578627c8f263c6f385d55a0d3e1237230137d306f888face329348849356bc5c8ce7cbf56ee6e200cf9d41efc2554045cb1d645cb3b18490b
7
+ data.tar.gz: acc57516bc9d1dc91c90766ea569369a973fa5a210e3f936a29142907e998013e534b487e818dbc6628e2fc27d4e858b73cbf71baa47dfc4bc53bc79cd5c577f
@@ -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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Pittman