haversack 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -5
- data/lib/haversack/item.rb +1 -1
- data/lib/haversack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cf37108921d996da5627939fc13908ccb719958853a6d9620c89fb2e0a0a360
|
4
|
+
data.tar.gz: 21f14e3402e28bdef0b0a4fda8504886a5a06468bf0ab11782ddba7a9ceec839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f496dd7d39b89a525eb35eee1a26a80997d9821a8543f002f3e27b8078cec6593de424bec8582177738dee1fe637c820c532cbe8f5991e6acf52dc804ff6a5a3
|
7
|
+
data.tar.gz: 0c36f081dac2c44173e92c3ebb0f24f2555d09e645976d629a831970a4b6ac59f9506222b33cdae4e904fa120cef6b3a7c45849398a7b8c1d942f8a557b5edd5
|
data/README.md
CHANGED
@@ -1,8 +1,31 @@
|
|
1
1
|
# Haversack
|
2
2
|
|
3
|
-
|
3
|
+
Haversack is an enumerable abstraction of a [Knapsack](https://en.wikipedia.org/wiki/Knapsack_problem).
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
#### Basic Usage:
|
8
|
+
```ruby
|
9
|
+
require 'haversack'
|
10
|
+
|
11
|
+
haversack = Sack.new(capacity: 10, weight: 10)
|
12
|
+
items = Array.new(10) { Haversack::Item.new(weight: 1, size: 1) }
|
13
|
+
|
14
|
+
haversack.contents = items
|
15
|
+
```
|
16
|
+
Only objects of the `Haversack::Item` class may be added to a haversack's contents.
|
17
|
+
|
18
|
+
#### Haversack provides constraints upon what items may be set as the knapsack contents:
|
19
|
+
```ruby
|
20
|
+
too_large = Array.new(haversack.capacity + 1) { Haversack::Item.new }
|
21
|
+
haversack.contents = too_large # => Haversack::KnapsackCapacityExceededError
|
22
|
+
```
|
23
|
+
|
24
|
+
#### Or you may add one item at a time
|
25
|
+
```ruby
|
26
|
+
item = Haversack::Item.new
|
27
|
+
haversack.push item if haversack.fits_item? item
|
28
|
+
```
|
6
29
|
|
7
30
|
## Installation
|
8
31
|
|
@@ -20,9 +43,6 @@ Or install it yourself as:
|
|
20
43
|
|
21
44
|
$ gem install haversack
|
22
45
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
46
|
|
27
47
|
## Development
|
28
48
|
|
data/lib/haversack/item.rb
CHANGED
data/lib/haversack/version.rb
CHANGED