gstin_validation 1.0.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 +7 -0
- data/lib/gstin_validation.rb +27 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c9f5a2dc56572c6a2c8267671f0ec4e2f84fa125b97ce542f6c770b6a5074e53
|
4
|
+
data.tar.gz: eb2393f5ec4e3ec3c183ab370d9129cbcb6fe566dae8f1db4d6f61f568c3375f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 317efed29c3f645dcb81764a020b4e23a70dfd857dceba72cca24bfeff8c9103278076abc18dd239ee15aa17b4e8072543e404db933148fc13193165428d1bfc
|
7
|
+
data.tar.gz: 63848014413398627dbdeb109fcfc7821ebd1b34a2b7a1ed92178ae762ce87b080c254f2753cfb47c9619c1c46a6c29819b8e9848f2f2bbcb817733db7b2aa7d
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class GstinValidation
|
2
|
+
def self.validate_gstin_pattern(number)
|
3
|
+
factor = 2
|
4
|
+
sum = 0
|
5
|
+
mod_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
6
|
+
checksum_digit = number[0..13]
|
7
|
+
mod_chars_collection = mod_chars.chars
|
8
|
+
gstin = checksum_digit.strip.upcase.chars
|
9
|
+
mod = mod_chars_collection.length
|
10
|
+
sum = calculate_sum(gstin, mod, factor, sum, mod_chars_collection)
|
11
|
+
checksum_digit_index = (mod - (sum % mod)) % mod
|
12
|
+
return true if mod_chars_collection[checksum_digit_index].eql? number[-1]
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.calculate_sum(gstin, mod, factor, sum, mod_chars_collection)
|
17
|
+
gstin.reverse.each do |gstin_character|
|
18
|
+
weight = -1
|
19
|
+
mod_chars_collection.each_with_index { |mod_character, index| weight = index if gstin_character.eql? mod_character }
|
20
|
+
digit = factor * weight
|
21
|
+
factor = factor == 2 ? 1 : 2
|
22
|
+
digit = (digit / mod) + (digit % mod)
|
23
|
+
sum += digit
|
24
|
+
end
|
25
|
+
sum
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gstin_validation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amit Kumar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.7'
|
27
|
+
description: gstin_validation validates Indian gstin numbers based on the check digit.
|
28
|
+
The last character in a gstin number is the checksum digit. Checksum digit is generated
|
29
|
+
based on the first 14 characters of the gstin number.
|
30
|
+
email: amitkumar2080799@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/gstin_validation.rb
|
36
|
+
homepage: https://rubygems.org/gems/gstin_validation
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.7.8
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Validates Indian Gstin number based on check digit
|
60
|
+
test_files: []
|