luhnmod10-native 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/luhnmod10/native/extconf.rb +4 -0
- data/ext/luhnmod10/native/native.c +41 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 574c49f33502fcc02feeb864edfab00a1d6f089c
|
4
|
+
data.tar.gz: 6572570c53c3e0b74e66328c77e73c440797a6c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f82d0394d6d960ce855ec2ee6bf27bcc9703ad61b83c5e8ada554b43d8753017d8b118cecfe45e94b08cd0baa31677d18cbdd8512598463ac2e51830a06fb492
|
7
|
+
data.tar.gz: 29c781df7474eccc9bc99186e0a9ad412813c6f3d366075f0787140b0c082e85ffaf5a62470a768d0e86141c5866f4d31b962d94eb4842a05cf4c3732e401a82
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
VALUE Luhnmod10 = Qnil;
|
4
|
+
VALUE Luhnmod10Native = Qnil;
|
5
|
+
|
6
|
+
void Init_native();
|
7
|
+
VALUE method_luhnmod10_native_valid(VALUE self, VALUE number);
|
8
|
+
|
9
|
+
void Init_native() {
|
10
|
+
if (rb_const_defined(rb_cObject, rb_intern("Luhnmod10"))) {
|
11
|
+
Luhnmod10 = rb_const_get(rb_cObject, rb_intern("Luhnmod10"));
|
12
|
+
} else {
|
13
|
+
Luhnmod10 = rb_define_module("Luhnmod10");
|
14
|
+
}
|
15
|
+
|
16
|
+
Luhnmod10Native = rb_define_module_under(Luhnmod10, "Native");
|
17
|
+
rb_define_singleton_method(Luhnmod10Native, "valid?", method_luhnmod10_native_valid, 1);
|
18
|
+
}
|
19
|
+
|
20
|
+
VALUE method_luhnmod10_native_valid(VALUE self, VALUE vNumber) {
|
21
|
+
unsigned int checksum = 0;
|
22
|
+
|
23
|
+
char *number = RSTRING_PTR(vNumber);
|
24
|
+
size_t numberLen = RSTRING_LEN(vNumber);
|
25
|
+
|
26
|
+
long i;
|
27
|
+
for (i = numberLen - 1; i >= 0; i -= 2) {
|
28
|
+
unsigned char n = number[i] - '0';
|
29
|
+
checksum += n;
|
30
|
+
}
|
31
|
+
for (i = numberLen - 2; i >= 0; i -= 2) {
|
32
|
+
unsigned char n = number[i] - '0';
|
33
|
+
n *= 2;
|
34
|
+
if (n > 9) {
|
35
|
+
n -= 9;
|
36
|
+
}
|
37
|
+
checksum += n;
|
38
|
+
}
|
39
|
+
|
40
|
+
return checksum%10 == 0 ? Qtrue : Qfalse;
|
41
|
+
}
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: luhnmod10-native
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leigh McCulloch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 11.2.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 11.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.1
|
55
|
+
description: A fast and simple in-place implementation of the luhn check algorithm
|
56
|
+
in Ruby using a C extension.
|
57
|
+
email:
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/luhnmod10/native/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ext/luhnmod10/native/extconf.rb
|
64
|
+
- ext/luhnmod10/native/native.c
|
65
|
+
homepage: https://github.com/luhnmod10/ruby-native
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.5.1
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: A fast and simple in-place implementation of the luhn check algorithm in
|
89
|
+
Ruby using a C extension.
|
90
|
+
test_files: []
|