stocker 1.0.9 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/stocker +3 -3
  3. data/lib/stocker.rb +113 -107
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1c9d2f2a217654e9341eca86530fef35724d6be
4
- data.tar.gz: 7ef250c09c48082524ba6894b8b56116bf4f282e
3
+ metadata.gz: 686956c7bc9f797fc08f15605611d577fc25b10f
4
+ data.tar.gz: 33982843ab23a9c96d18de1f961b5c106a2770e3
5
5
  SHA512:
6
- metadata.gz: b4938e90b33fb6b1064c27aafbb81e9ce9960fd63ff2ea99920d423520f7f27c7bcd19f2ba8e19d84b4e81339a8c10f882a0f29af92a46bd9b4d01a46eb260f0
7
- data.tar.gz: 540aa8337ddba4581b6ac634556da5f1fb3517ab09f9764243428dba23f400ae71f6cc8781179f0af0c3afe6ee744e2795d58f4a892e9ecbb14485568f7b299f
6
+ metadata.gz: f528c468255b345d6a42670949bcfe484f85bb2825223682460ff46938a792ac7c6d8c21511711443a33a1e5ed2eb8dc4bfa0aeecc7d7808e7f6f9988bc8518b
7
+ data.tar.gz: 1fb2f3187a81f17d4367bd47512a4fcbff34657963a9fbddef5864b5290857ad356cf74510f0d76f7c74058ec6634d8a0b1c627e172c89dcad758d2c9506dc48
data/bin/stocker CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'stocker'
3
+ require File.dirname(__FILE__) + '/../lib/stocker.rb'
4
4
 
5
- Stocker.start(ARGV)
6
- Stocker.save
5
+ Stocker::Generator.start(ARGV)
6
+ Stocker::Generator.save
data/lib/stocker.rb CHANGED
@@ -6,13 +6,14 @@ require 'thor'
6
6
  require 'titleize'
7
7
 
8
8
  # @author Brandon Pittman
9
+ module Stocker
10
+ class Generator < Thor
11
+ trap("SIGINT") { exit 0 }
9
12
 
10
- class Stocker < Thor
11
- trap("SIGINT") { exit 0 }
13
+ @@path = nil
12
14
 
13
- @@path = nil
15
+ private
14
16
 
15
- no_commands do
16
17
  def self.check_for_dropbox
17
18
  home = Dir.home
18
19
  db = "#{Dir.home}/Dropbox"
@@ -20,138 +21,143 @@ class Stocker < Thor
20
21
  db_path = Pathname.new(db)
21
22
  @@path = db_path || home_path
22
23
  end
23
- end
24
24
 
25
- check_for_dropbox
26
- @@yaml = Pathname.new("#{@@path}/.stocker.yml")
27
- `touch #{@@yaml}`
28
- @@stock = YAML.load(@@yaml.read)
29
- @@stock = {} unless @@stock.class == Hash
25
+ public
26
+
27
+ check_for_dropbox
28
+ #TODO: mv .stocker.yml .stocker.yaml if .stocker.yml exists
29
+ @@yaml = Pathname.new("#{@@path}/.stocker.yaml")
30
+ `touch #{@@yaml}`
31
+ @@stock = YAML.load(@@yaml.read)
32
+ @@stock = {} unless @@stock.class == Hash
33
+
34
+ private
30
35
 
31
- no_commands do
32
36
  def match_name(item)
33
37
  @@stock.each_key { |key| @@item = key if key =~ /#{item}/ }
34
38
  end
35
- end
36
39
 
37
- desc "new ITEM TOTAL", "Add ITEM with TOTAL on hand to inventory."
38
- option :url, :aliases => :u, :default => 'http://amazon.com'
39
- option :minimum, :aliases => :m, :default => 1
40
- def new(item, total)
41
- @@stock[item] = {'total' => total.to_i, 'min' => options[:min].to_i, 'url' => options[:url], 'checked' => Time.now}
42
- end
40
+ public
43
41
 
44
- desc "delete ITEM", "Delete ITEM from inventory."
45
- def delete(item)
46
- match_name(item)
47
- @@stock.delete(@@item)
48
- end
42
+ desc "new ITEM TOTAL", "Add ITEM with TOTAL on hand to inventory."
43
+ option :url, :aliases => :u, :default => 'http://amazon.com'
44
+ option :minimum, :aliases => :m, :default => 1
45
+ def new(item, total)
46
+ @@stock[item] = {'total' => total.to_i, 'min' => options[:min].to_i, 'url' => options[:url], 'checked' => Time.now}
47
+ end
48
+
49
+ desc "delete ITEM", "Delete ITEM from inventory."
50
+ def delete(item)
51
+ match_name(item)
52
+ @@stock.delete(@@item)
53
+ end
49
54
 
50
- desc "check", "Check for low stock items."
51
- def check
52
- @@stock.each do |key, value|
53
- value["checked"] = Time.now
54
- if value["total"] <= value["min"]
55
- puts "You're running low on #{key}!"
56
- buy(key)
55
+ desc "check", "Check for low stock items."
56
+ def check
57
+ @@stock.each do |key, value|
58
+ value["checked"] = Time.now
59
+ if value["total"] <= value["min"]
60
+ puts "You're running low on #{key}!"
61
+ buy(key)
62
+ end
57
63
  end
58
64
  end
59
- end
60
65
 
61
- desc "total ITEM TOTAL", "Set TOTAL of ITEM."
62
- def total(item, total)
63
- match_name(item)
64
- @@stock[@@item]["total"] = total.to_i
65
- time(item)
66
- end
66
+ desc "total ITEM TOTAL", "Set TOTAL of ITEM."
67
+ def total(item, total)
68
+ match_name(item)
69
+ @@stock[@@item]["total"] = total.to_i
70
+ time(item)
71
+ end
72
+
73
+ private
67
74
 
68
- no_commands do
69
75
  def time(item)
70
76
  match_name(item)
71
77
  @@stock[@@item]["checked"] = Time.now
72
78
  end
73
- end
74
79
 
75
- no_commands do
76
80
  def self.save
77
81
  @@yaml.open('w') { |t| t << @@stock.to_yaml }
78
82
  # @@yaml.write(@@stock.to_yaml)
79
83
  end
80
- end
81
84
 
82
- desc "url ITEM URL", "Set URL of ITEM."
83
- def url(item, url)
84
- match_name(item)
85
- @@stock[@@item]["url"] = url
86
- time(item)
87
- end
85
+ public
88
86
 
89
- desc "buy ITEM", "Open link to buy ITEM"
90
- def buy(item)
91
- match_name(item)
92
- `open -a Safari #{@@stock[@@item]["url"]}`
93
- end
94
-
95
- desc "min ITEM MINIMUM", "Set minimum acceptable amount for ITEM."
96
- def min(item, min)
97
- match_name(item)
98
- @@stock[@@item]["min"] = min.to_i
99
- end
87
+ desc "url ITEM URL", "Set URL of ITEM."
88
+ def url(item, url)
89
+ match_name(item)
90
+ @@stock[@@item]["url"] = url
91
+ time(item)
92
+ end
100
93
 
101
- desc "count", "Take an interactive inventory."
102
- def count
103
- @@stock.each do |key, value|
104
- value["checked"] = Time.now
105
- value["total"] = ask("#{key.titlecase}:", *args).to_i
94
+ desc "buy ITEM", "Open link to buy ITEM"
95
+ def buy(item)
96
+ match_name(item)
97
+ `open -a Safari #{@@stock[@@item]["url"]}`
106
98
  end
107
- invoke :check
108
- end
109
99
 
110
- desc "csv", "Write entire inventory as CSV."
111
- def csv
112
- @@stock.each { |key, value| puts "#{key.titlecase},#{value['total']},#{value['min']},#{value['url']},#{value['checked']}" }
113
- end
100
+ desc "min ITEM MINIMUM", "Set minimum acceptable amount for ITEM."
101
+ def min(item, min)
102
+ match_name(item)
103
+ @@stock[@@item]["min"] = min.to_i
104
+ end
114
105
 
115
- desc "list", "List all inventory items and total on hand."
116
- long_desc <<-LONGDESC
117
- List outputs a colorized list of all your inventory items.
118
-
119
- Items that are well-stocked are green, items that are at the minimum acceptable will be yellow and out of stock items are red.
120
-
121
- The items are smartly organized by the difference between the 'on-hand' count and the minimum acceptable amount.
122
-
123
- 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' 22. So even though I have more beer, it will show up below chips in the list.
124
- LONGDESC
125
- def list
126
- begin
127
- @header = [[set_color("Item", :white), set_color("Total", :white)], [set_color("=================", :white), set_color("=====", :white)]]
128
- @green = []
129
- @yellow = []
130
- @yellow2 = []
131
- @green2 = []
132
- @red = []
133
- @red2 = []
106
+ desc "count", "Take an interactive inventory."
107
+ def count
134
108
  @@stock.each do |key, value|
135
- if value['total'] > value['min']
136
- @green += [[key.titlecase,value['total'], value['total']-value['min']]]
137
- elsif value['total'] == value['min']
138
- @yellow += [[key.titlecase,value['total'], value['total']-value['min']]]
139
- else
140
- @red += [[key.titlecase,value['total'], value['total']-value['min']]]
109
+ value["checked"] = Time.now
110
+ value["total"] = ask("#{key.titlecase}:", *args).to_i
111
+ end
112
+ invoke :check
113
+ end
114
+
115
+ desc "csv", "Write entire inventory as CSV."
116
+ def csv
117
+ @@stock.each { |key, value| puts "#{key.titlecase},#{value['total']},#{value['min']},#{value['url']},#{value['checked']}" }
118
+ end
119
+
120
+ desc "list", "List all inventory items and total on hand."
121
+ long_desc <<-LONGDESC
122
+ List outputs a colorized list of all your inventory items.
123
+
124
+ Items that are well-stocked are green, items that are at the minimum acceptable will be yellow and out of stock items are red.
125
+
126
+ The items are smartly organized by the difference between the 'on-hand' count and the minimum acceptable amount.
127
+
128
+ 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.
129
+ LONGDESC
130
+ def list
131
+ begin
132
+ @header = [[set_color("Item", :white), set_color("Total", :white)], [set_color("=================", :white), set_color("=====", :white)]]
133
+ @green = []
134
+ @yellow = []
135
+ @yellow2 = []
136
+ @green2 = []
137
+ @red = []
138
+ @red2 = []
139
+ @@stock.each do |key, value|
140
+ if value['total'] > value['min']
141
+ @green += [[key.titlecase,value['total'], value['total']-value['min']]]
142
+ elsif value['total'] == value['min']
143
+ @yellow += [[key.titlecase,value['total'], value['total']-value['min']]]
144
+ else
145
+ @red += [[key.titlecase,value['total'], value['total']-value['min']]]
146
+ end
141
147
  end
148
+ @green.sort_by! { |a,b,c| c }
149
+ @yellow.sort_by! { |a,b,c| c }
150
+ @red.sort_by! { |a,b,c| c }
151
+ @green.reverse!
152
+ @yellow.reverse!
153
+ @red.reverse!
154
+ @green.each { |a,b| @green2 += [[set_color(a, :green), set_color(b, :green)]] }
155
+ @yellow.each { |a,b| @yellow2 += [[set_color(a, :yellow), set_color(b, :yellow)]] }
156
+ @red.each { |a,b| @red2 += [[set_color(a, :red), set_color(b, :red)]] }
157
+ print_table(@header + @green2 + @yellow2 + @red2,{indent: 2})
158
+ rescue Exception => e
159
+ puts "Inventory empty"
142
160
  end
143
- @green.sort_by! { |a,b,c| c }
144
- @yellow.sort_by! { |a,b,c| c }
145
- @red.sort_by! { |a,b,c| c }
146
- @green.reverse!
147
- @yellow.reverse!
148
- @red.reverse!
149
- @green.each { |a,b| @green2 += [[set_color(a, :green), set_color(b, :green)]] }
150
- @yellow.each { |a,b| @yellow2 += [[set_color(a, :yellow), set_color(b, :yellow)]] }
151
- @red.each { |a,b| @red2 += [[set_color(a, :red), set_color(b, :red)]] }
152
- print_table(@header + @green2 + @yellow2 + @red2,{indent: 2})
153
- rescue Exception => e
154
- puts "Inventory empty"
155
161
  end
156
162
  end
157
- end
163
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Pittman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2014-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -47,7 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - bin/stocker
49
49
  - lib/stocker.rb
50
- homepage: http://www.brandonpittman.net
50
+ homepage: http://github.com/brandonpittman/stocker
51
51
  licenses:
52
52
  - MIT
53
53
  metadata: {}
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  requirements: []
69
69
  rubyforge_project:
70
- rubygems_version: 2.2.2
70
+ rubygems_version: 2.2.1
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: stocker is a lightweight home inventory application.