plu 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +9 -0
- data/lib/plu.rb +40 -0
- data/lib/plu/version.rb +3 -0
- data/plu.gemspec +24 -0
- data/test/plu_test.rb +43 -0
- data/test/test_helper.rb +4 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c7db37a09ef1d1c9236629e968745d9f800b4ed
|
4
|
+
data.tar.gz: 45d163010e98d1e374b6a32e6f5d7468f598852d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0cbda8ebcd9ec0097801e65f6a1a620f6b4231e606e27efec169b82fd211f7da42530ccb2728c553f975b20063daa85a6a8dbf553d6ec5ef76303f2c3c1dc978
|
7
|
+
data.tar.gz: 0fa6f1ca72a00a28e96f6f6e341a50828179aa70351b9a33549648c78f07ec4ad029845076ac90bf78ad89fe7c0634647457e0b65089a3165279991914fe8297
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Kane
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# PLU
|
2
|
+
|
3
|
+
[Price look-up codes](http://en.wikipedia.org/wiki/Price_look-up_code) made easy
|
4
|
+
|
5
|
+
- :watermelon: 4032
|
6
|
+
- :banana: 4011
|
7
|
+
- :grapes: 4023
|
8
|
+
|
9
|
+
## How To Use
|
10
|
+
|
11
|
+
List known PLUs (coming soon)
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
PLU.all
|
15
|
+
```
|
16
|
+
|
17
|
+
Get name from PLU (coming soon)
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
PLU.new(4011).name # Bananas
|
21
|
+
```
|
22
|
+
|
23
|
+
Check if valid
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
PLU.new(2000).valid? # false
|
27
|
+
```
|
28
|
+
|
29
|
+
### 5-Digit PLUs
|
30
|
+
|
31
|
+
For PLUs with 5 digits, the first digit has a special meaning: 9 specifies organic, and 8 specifies genetically modified.
|
32
|
+
|
33
|
+
- 4011 - Bananas
|
34
|
+
- 94011 - Organic bananas
|
35
|
+
- 84011 - Genetically modified bananas
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
PLU.new(94011).organic? # true
|
39
|
+
PLU.new(84011).gm? # true
|
40
|
+
```
|
41
|
+
|
42
|
+
## Installation
|
43
|
+
|
44
|
+
Add this line to your Gemfile:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
gem "plu"
|
48
|
+
```
|
49
|
+
|
50
|
+
And run:
|
51
|
+
|
52
|
+
```sh
|
53
|
+
bundle
|
54
|
+
```
|
55
|
+
|
56
|
+
## TODO
|
57
|
+
|
58
|
+
- add items
|
59
|
+
|
60
|
+
## Resources
|
61
|
+
|
62
|
+
- [IFPS 2012 Users Guide](http://www.plucodes.com/docs/Users_Guide_July_2012_FINAL.pdf)
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/plu.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class PLU
|
2
|
+
|
3
|
+
def initialize(number)
|
4
|
+
@number = number.to_s
|
5
|
+
end
|
6
|
+
|
7
|
+
def valid?
|
8
|
+
/\A[89]?[34]\d{3}\z/.match(@number)
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO more items
|
12
|
+
def name
|
13
|
+
self.class.all[base]
|
14
|
+
end
|
15
|
+
|
16
|
+
def organic?
|
17
|
+
modifier == "9"
|
18
|
+
end
|
19
|
+
|
20
|
+
def gm?
|
21
|
+
modifier == "8"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.all
|
25
|
+
{
|
26
|
+
"4011" => "Bananas"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def base
|
33
|
+
@number[-4..-1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def modifier
|
37
|
+
@number[-5]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/plu/version.rb
ADDED
data/plu.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'plu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "plu"
|
8
|
+
spec.version = PLU::VERSION
|
9
|
+
spec.authors = ["Andrew Kane"]
|
10
|
+
spec.email = ["andrew@chartkick.com"]
|
11
|
+
spec.description = %q{Price look-up codes made easy}
|
12
|
+
spec.summary = %q{Price look-up codes made easy}
|
13
|
+
spec.homepage = "https://github.com/ankane/plu"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
end
|
data/test/plu_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class TestPLU < Minitest::Test
|
4
|
+
|
5
|
+
def test_plu
|
6
|
+
plu = PLU.new(4011)
|
7
|
+
assert plu.valid?
|
8
|
+
assert !plu.organic?
|
9
|
+
assert !plu.gm?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_organic
|
13
|
+
assert PLU.new(94011).organic?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_gm
|
17
|
+
assert PLU.new(84011).gm?
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_invalid
|
21
|
+
assert !PLU.new(2000).valid?
|
22
|
+
assert !PLU.new(5000).valid?
|
23
|
+
assert !PLU.new(400).valid?
|
24
|
+
assert !PLU.new(40111).valid?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_invalid_modifier
|
28
|
+
assert !PLU.new(74011).valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_name
|
32
|
+
assert_equal "Bananas", PLU.new(94011).name
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_no_name
|
36
|
+
assert_nil PLU.new(4000).name
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_all
|
40
|
+
assert_kind_of Hash, PLU.all
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-18 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
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
|
+
description: Price look-up codes made easy
|
56
|
+
email:
|
57
|
+
- andrew@chartkick.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/plu.rb
|
68
|
+
- lib/plu/version.rb
|
69
|
+
- plu.gemspec
|
70
|
+
- test/plu_test.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
homepage: https://github.com/ankane/plu
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.0
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Price look-up codes made easy
|
96
|
+
test_files:
|
97
|
+
- test/plu_test.rb
|
98
|
+
- test/test_helper.rb
|