haversack 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d71edcac6f25267e658d600c14549b4be32fe255a2bfcbf00a2c8c73e8d7a3c6
4
- data.tar.gz: e895b3122a414660d8fbf52a1d64c8e0b08c920bb13bef8ce63168fd483499e5
3
+ metadata.gz: 3cf37108921d996da5627939fc13908ccb719958853a6d9620c89fb2e0a0a360
4
+ data.tar.gz: 21f14e3402e28bdef0b0a4fda8504886a5a06468bf0ab11782ddba7a9ceec839
5
5
  SHA512:
6
- metadata.gz: ea48edcbbd0f07b31b119fec4000d8c596a85368b02ff37e2f9832279e14a5eef5be49bc2ea04e314dfd1a8b5e5a1674e0c79c3c5865b9b6a253ed7973676a1c
7
- data.tar.gz: 6a910b9216773f852aedacae2a96d0aa11d4997de9a8665374c024db50811a2c7dd6d1171c2d683c273f244aac2f16570cbc92a441a3a17d09d33002f8d43c15
6
+ metadata.gz: f496dd7d39b89a525eb35eee1a26a80997d9821a8543f002f3e27b8078cec6593de424bec8582177738dee1fe637c820c532cbe8f5991e6acf52dc804ff6a5a3
7
+ data.tar.gz: 0c36f081dac2c44173e92c3ebb0f24f2555d09e645976d629a831970a4b6ac59f9506222b33cdae4e904fa120cef6b3a7c45849398a7b8c1d942f8a557b5edd5
data/README.md CHANGED
@@ -1,8 +1,31 @@
1
1
  # Haversack
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/haversack`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Haversack is an enumerable abstraction of a [Knapsack](https://en.wikipedia.org/wiki/Knapsack_problem).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
 
@@ -4,7 +4,7 @@ module Haversack
4
4
  attr_accessor :size
5
5
  attr_accessor :data
6
6
 
7
- def initialize(weight:, size: 1, data: nil)
7
+ def initialize(weight: 1, size: 1, data: nil)
8
8
  @weight = weight
9
9
  @size = size
10
10
  @data = data
@@ -1,3 +1,3 @@
1
1
  module Haversack
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haversack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alex0112