qr_emv 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cae072227a5ee3a71ffc0be737b2e68ce91336ed6b1732c42fb5c53f1b37f4d0
4
+ data.tar.gz: 263a8bbb08958dbca45ac38fcc4a1ed4e1762aae06e5171cd6e5d70c803b6da6
5
+ SHA512:
6
+ metadata.gz: ea8ae9da832d59c1bba6e342cc21d04768488798b00743e7b1f83fd554e0ec3f2d5031f907c7f0e3b8ad30cb56445ed182ec1265682ae60f413629d0787866ca
7
+ data.tar.gz: 6693fe7c25ea6d292ef2d5fa0ece38f9e71767d503ef71595a69c09b2dff4d7c4a95aa92d0bcba517c3d9ce6687098266de37a38bc02b7a202cb000f12cf4abe
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-09-17
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Jeffrey de Lara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # QrEmv
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/qr_emv`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qr_emv.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QrEmv
4
+ VERSION = "0.1.0"
5
+ end
data/lib/qr_emv.rb ADDED
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "qr_emv/version"
4
+
5
+ module QrEmv
6
+ class Error < StandardError; end
7
+
8
+ class Parser
9
+ attr_accessor :raw_string, :root, :merchant_info
10
+
11
+ def initialize(raw_string:)
12
+ @raw_string = raw_string
13
+ @root = {}
14
+ @merchant_info = {}
15
+
16
+ parse_root
17
+ parse_merchant_info
18
+ end
19
+
20
+ def parse_root
21
+ attrs = parse(data: @raw_string)
22
+
23
+ @root = attrs
24
+ end
25
+
26
+ def parse_merchant_info
27
+ parsed_merchant_info = parse(data: @root['27'])
28
+
29
+ @merchant_info = parsed_merchant_info
30
+ end
31
+
32
+ private
33
+
34
+ def parse(data:)
35
+ attrs = {}
36
+ current_cursor = :id
37
+ ids = []
38
+ lengths = []
39
+ values = []
40
+
41
+ data.chars.each do |c|
42
+ case current_cursor
43
+ when :id
44
+ ids << c
45
+
46
+ current_cursor = :length if ids.size == 2
47
+ when :length
48
+ lengths << c
49
+
50
+ current_cursor = :value if lengths.size == 2
51
+ when :value
52
+ value_counter = lengths.join.to_i
53
+ values << c
54
+
55
+ if value_counter == values.size
56
+ attrs[ids.join] = values.join
57
+
58
+ ids = []
59
+ lengths = []
60
+ values = []
61
+
62
+ current_cursor = :id
63
+ end
64
+ end
65
+ end
66
+
67
+ attrs
68
+ end
69
+ end
70
+ end
71
+
data/sig/qr_emv.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module QrEmv
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qr_emv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeffrey de Lara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Parses a qr string according to EMV QRCPS
14
+ email:
15
+ - jeffreytdelara@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/qr_emv.rb
27
+ - lib/qr_emv/version.rb
28
+ - sig/qr_emv.rbs
29
+ homepage: https://github.com/jeffdelara/qr_emv
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ allowed_push_host: https://rubygems.org
34
+ homepage_uri: https://github.com/jeffdelara/qr_emv
35
+ source_code_uri: https://github.com/jeffdelara/qr_emv
36
+ changelog_uri: https://github.com/jeffdelara/qr_emv/blob/main/CHANGELOG.md
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.5.17
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: QR string parser for EMV QR Code Specification for Payment Systems (EMV QRCPS)
56
+ test_files: []