GS1 provides the tools to make your code GS1 compliant.
Add this line to your application's Gemfile:
gem 'gs1'
And then execute:
$ bundle
Or install it yourself as:
$ gem install gs1
Follow the examples below to start using the gem.
There are some configuration you can do before start using this lib.
GS1.configure do |config|
config.company_prefix = '123456789'
config.barcode_separator = '~' # Default is "\u001E"
config.ignore_extra_barcode_elements = false # Default is true
end
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"
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"}
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.
- 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
Unreleased
section at the top - Add a new reference link for the new section at the bottom of the changelog
- Update the
Unreleased
reference link at the bottom of the changelog
To publish a new version of this gem, follow the steps below:
-
Update the version in the version.rb file
-
Run
bundle
to 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 mode -
Check the GitHub Release and then publish it
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.
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.
-
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_classes
-
Commit all changed files
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Gs1 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.