GS1
GS1 provides the tools to make your code GS1 compliant.
Installation
Add this line to your application's Gemfile:
gem 'gs1'
And then execute:
$ bundle
Or install it yourself as:
$ gem install gs1
Usage
Follow the examples below to start using the gem.
Configuration
There are some configuration you can do before start using this lib.
GS1.configure do |config|
config.company_prefix = '123456789'
config. = '~' # Default is "\u001E"
config. = false # Default is true
end
Application identifiers
To access the defined application identifier:
GS1::AI::GTIN # => "01"
or via the class:
GS1::ExpirationDate::AI # => "17"
GS1::ExpirationDate.ai # => "17"
To get the class from a numeric id:
GS1::AI_CLASSES[GS1::AI::BATCH_LOT] # => "GS1::Batch"
Healthcare barcodes
To initialize a healthcare barcode from scan input:
GS1::Barcode::Healthcare.from_scan("01034531200000111719112510ABCD1234\u001E2110")
# => #<GS1::Barcode::Healthcare:0x007fe1b99ea280
# @gtin=#<GS1::GTIN:0x007fe1b99e9a10 @errors=[], @data="03453120000011">,
# @expiration_date=#<GS1::ExpirationDate:0x007fe1b99e8700 @errors=[], @data="191125">,
# @batch=#<GS1::Batch:0x007fe1b99e3b10 @errors=[], @data="ABCD1234">,
# @serial_number=#<GS1::SerialNumber:0x007fe1b99e2670 @errors=[], @data="10">,
# @errors=[]>
or just get the attributes
GS1::Barcode::Healthcare.from_scan("01034531200000111719112510ABCD1234\u001E2110")
# => {:gtin=>"03453120000011", :expiration_date=>"191125", :batch=>"ABCD1234", :serial_number=>"10"}
Development
After checking out the repo, run bin/setup to install dependencies. Then, run
rake spec to run the tests. You can also run bin/console for an interactive
prompt that will allow you to experiment.
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.
Creating a Release
Update the Changelog
- Rename the Unreleased section to match the version that is being released
- Add the current date in the section from previous step. See existing entries
- Add a new section for the
Unreleasedsection at the top - Add a new reference link for the new section at the bottom of the changelog
- Update the
Unreleasedreference link at the bottom of the changelog
Publish New Version of Gem
To publish a new version of this gem, follow the steps below:
- Update the version in the version.rb file
- Run
bundleto update Gemfile.lock Commit and push the changes
Run
rake release:initiate. This initiates a new release by creating a Git tag with the version specified in version.rb. It will then push the Git tag. This will trigger a job in the CI pipeline, which will build the gem and publish it to https://rubygems.org. It will also create a GitHub Release, in draft modeCheck the GitHub Release and then publish it
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/apoex/gs1. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Changelog
The changelog is maintained in the CHANGELOG.md file, following the Keep a Changelog format. The changelog is updated incrementally. That is, for every new feature or bugfix, add an entry to the changelog. New entries are added below the Unreleased section, with an appropriate sub header.
Update Known Application Identifiers
Download the latest version of the GS1 syntax dictionary
Place the syntax dictionary in the gs1-syntax-dictionary.txt file
Run the script to generate the AI classes from the syntax dictionary:
./bin/generate_ai_classesCommit all changed files
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Gs1 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.