inventory-cli 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44fbe8616dbfa58b7210503173a573dd3120343f
4
+ data.tar.gz: a5b1793a96b890dd847d90c2208fb478f2134fa4
5
+ SHA512:
6
+ metadata.gz: 17dae877aee8456ac258f901f58a553dd25d0bb072089f0b57bb9d0d26876f175ebfb0b246fd1a37560995ab5fb28d98c463b6d6f90438855ebfa5edc0da4322
7
+ data.tar.gz: 2dca8ade19966c70d73cf7317eac8e2656268a8700c7f29f253d6286a3ff755f0a03ec1148edb223b7a4bb4018ee5793a37fed3cba7a751596c0d755097fc73c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
5
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inventory.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Skyler Layne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Inventory
2
+ [![Build
3
+ Status](https://travis-ci.org/skylerto/inventory.svg?branch=gemify)](https://travis-ci.org/skylerto/inventory)
4
+ [![Code
5
+ Climate](https://codeclimate.com/repos/559e8e1869568031df008616/badges/3d6f92dd7401a8c34ce6/gpa.svg)](https://codeclimate.com/repos/559e8e1869568031df008616/feed)
6
+ [![Coverage
7
+ Status](https://coveralls.io/repos/skylerto/inventory/badge.svg?branch=master&service=github)](https://coveralls.io/github/skylerto/inventory?branch=master)
8
+ [![Dependency
9
+ Status](https://gemnasium.com/skylerto/inventory.svg)](https://gemnasium.com/skylerto/inventory)
10
+
11
+ Manage inventory with this.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'inventory'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install inventory
28
+
29
+ ## Usage
30
+
31
+ no
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/skylerto/inventory.
42
+
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+
48
+ ### To do
49
+
50
+ - Add some way to control orders, look at how rails goes about `rails generate
51
+ ...` vs `rails server` for inspiration.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "inventory"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'inventory/cli'
3
+
4
+ Inventory::CLI.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'inventory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "inventory-cli"
8
+ spec.version = Inventory::VERSION
9
+ spec.authors = ["skylerto"]
10
+ spec.email = ["skylerclayne@gmail.com\n"]
11
+
12
+ spec.summary = %q{An inventory management gem}
13
+ spec.description = %q{A gem that lets you control the flow of products, and orders through invoices}
14
+ spec.homepage = "https://github.com/skylerto/inventory"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ # Development dependencies
31
+ spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec"
34
+ spec.add_development_dependency "cucumber"
35
+ spec.add_development_dependency "aruba"
36
+
37
+ # Production dependencies
38
+ spec.add_dependency "thor"
39
+ end
@@ -0,0 +1,7 @@
1
+ require "inventory/version"
2
+ require "inventory/inventory"
3
+ #require "inventory/bag"
4
+
5
+ module Inventory
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,86 @@
1
+ require_relative 'exceptions'
2
+
3
+ class Bag
4
+ include Enumerable
5
+ # Create the bag
6
+ def initialize
7
+ @bag = Hash.new
8
+ end
9
+
10
+ def size
11
+ @bag.size
12
+ end
13
+
14
+ ## => Booleans
15
+ #Do we have the item?
16
+ def has?(amount, item)
17
+ @bag.has_key?(item) and @bag[item] >= amount
18
+ end
19
+
20
+ def empty?
21
+ @bag.size == 0
22
+ end
23
+
24
+ ## => Insertions / Deletions
25
+ def add(amount, item)
26
+
27
+ unless amount > 0
28
+ raise Exceptions::NotEnoughError
29
+ "Value must be greater than 0"
30
+ end
31
+ if @bag.has_key?(item)
32
+ @bag[item] += amount
33
+ else
34
+ @bag[item] = amount
35
+ end
36
+ end
37
+
38
+ def add_all(other)
39
+ other.each do |item, amount|
40
+ self.add(amount, item)
41
+ end
42
+ end
43
+
44
+ # Someone bought my things
45
+ def remove(amount, item)
46
+ if @bag.empty?
47
+ puts "empty bag"
48
+ return
49
+ elsif !self.has?(amount, item)
50
+ puts "not enough"
51
+ else
52
+ @bag[item] -= amount
53
+ end
54
+ end
55
+
56
+ def remove_all(other)
57
+ if @bag.empty?
58
+ puts "empty bag"
59
+ return
60
+ else
61
+ other.each do |item, amount|
62
+ self.remove(amount, item)
63
+ end
64
+ end
65
+ end
66
+
67
+ ## => Iterating
68
+ def each(&block)
69
+ @bag.each(&block)
70
+ end
71
+
72
+ ## => Formating
73
+ # Let me know how many things are in my bag man.
74
+ def print
75
+ buffer = []
76
+ if @bag.empty?
77
+ buffer << "Bag is empty"
78
+ else
79
+ buffer << "Current Inventory"
80
+ @bag.each do |item, amount|
81
+ buffer << " #{item}: #{amount}"
82
+ end
83
+ end
84
+ buffer
85
+ end
86
+ end
@@ -0,0 +1,18 @@
1
+ require 'thor'
2
+ require 'inventory'
3
+ module Inventory
4
+ class CLI < Thor
5
+
6
+ desc "add AMOUNT ITEM", "Add an amount of an item"
7
+ def add(amount, item)
8
+ System::Inventory.add(amount.to_i, item)
9
+ puts System::Inventory.print
10
+ end
11
+
12
+ desc "remove AMOUNT ITEM", "Remove an amount of an item"
13
+ def remove(amount, item)
14
+ System::Inventory.remove(amount.to_i, item)
15
+ puts System::Inventory.print
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Exceptions
2
+ class NotEnoughError < StandardError; end
3
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'bag'
2
+ require 'singleton'
3
+
4
+ module System
5
+ class Inventory
6
+ include Singleton
7
+
8
+ @bag = Bag.new
9
+
10
+ def initialize()
11
+ @bag = Bag.new
12
+ end
13
+
14
+ def self.add(amount, item)
15
+ @bag.add(amount, item)
16
+ end
17
+
18
+ def self.add_all(bag)
19
+ @bag.add_all(bag)
20
+ end
21
+
22
+ def self.remove_all(bag)
23
+ @bag.remove_all(bag)
24
+ end
25
+
26
+ def self.remove(amount, item)
27
+ @bag.remove(amount, item)
28
+ end
29
+
30
+ def self.has?(amount, item)
31
+ @bag.has?(amount, item)
32
+ end
33
+
34
+ def self.print
35
+ @bag.print
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Inventory
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inventory-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - skylerto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A gem that lets you control the flow of products, and orders through
98
+ invoices
99
+ email:
100
+ - |
101
+ skylerclayne@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/inventory
115
+ - bin/setup
116
+ - inventory.gemspec
117
+ - lib/inventory.rb
118
+ - lib/inventory/bag.rb
119
+ - lib/inventory/cli.rb
120
+ - lib/inventory/exceptions.rb
121
+ - lib/inventory/inventory.rb
122
+ - lib/inventory/version.rb
123
+ homepage: https://github.com/skylerto/inventory
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.5
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: An inventory management gem
147
+ test_files: []
148
+ has_rdoc: