beid_parser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +167 -0
- data/README.md +36 -0
- data/Rakefile +5 -0
- data/lib/beid_parser.rb +10 -0
- data/lib/beid_parser/beid.rb +86 -0
- data/lib/beid_parser/version.rb +3 -0
- data/spec/beid_spec.rb +6 -0
- data/spec/spec_helper.rb +7 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
Copyright (C) 2012 Thibault Poncelet <thibaultponcelet@gmail.com>
|
2
|
+
|
3
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
4
|
+
Version 3, 29 June 2007
|
5
|
+
|
6
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
7
|
+
Everyone is permitted to copy and distribute verbatim copies
|
8
|
+
of this license document, but changing it is not allowed.
|
9
|
+
|
10
|
+
|
11
|
+
This version of the GNU Lesser General Public License incorporates
|
12
|
+
the terms and conditions of version 3 of the GNU General Public
|
13
|
+
License, supplemented by the additional permissions listed below.
|
14
|
+
|
15
|
+
0. Additional Definitions.
|
16
|
+
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
19
|
+
General Public License.
|
20
|
+
|
21
|
+
"The Library" refers to a covered work governed by this License,
|
22
|
+
other than an Application or a Combined Work as defined below.
|
23
|
+
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
27
|
+
of using an interface provided by the Library.
|
28
|
+
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
30
|
+
Application with the Library. The particular version of the Library
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
32
|
+
Version".
|
33
|
+
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
37
|
+
based on the Application, and not on the Linked Version.
|
38
|
+
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
40
|
+
object code and/or source code for the Application, including any data
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
43
|
+
|
44
|
+
1. Exception to Section 3 of the GNU GPL.
|
45
|
+
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
48
|
+
|
49
|
+
2. Conveying Modified Versions.
|
50
|
+
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
53
|
+
that uses the facility (other than as an argument passed when the
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
55
|
+
version:
|
56
|
+
|
57
|
+
a) under this License, provided that you make a good faith effort to
|
58
|
+
ensure that, in the event an Application does not supply the
|
59
|
+
function or data, the facility still operates, and performs
|
60
|
+
whatever part of its purpose remains meaningful, or
|
61
|
+
|
62
|
+
b) under the GNU GPL, with none of the additional permissions of
|
63
|
+
this License applicable to that copy.
|
64
|
+
|
65
|
+
3. Object Code Incorporating Material from Library Header Files.
|
66
|
+
|
67
|
+
The object code form of an Application may incorporate material from
|
68
|
+
a header file that is part of the Library. You may convey such object
|
69
|
+
code under terms of your choice, provided that, if the incorporated
|
70
|
+
material is not limited to numerical parameters, data structure
|
71
|
+
layouts and accessors, or small macros, inline functions and templates
|
72
|
+
(ten or fewer lines in length), you do both of the following:
|
73
|
+
|
74
|
+
a) Give prominent notice with each copy of the object code that the
|
75
|
+
Library is used in it and that the Library and its use are
|
76
|
+
covered by this License.
|
77
|
+
|
78
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
79
|
+
document.
|
80
|
+
|
81
|
+
4. Combined Works.
|
82
|
+
|
83
|
+
You may convey a Combined Work under terms of your choice that,
|
84
|
+
taken together, effectively do not restrict modification of the
|
85
|
+
portions of the Library contained in the Combined Work and reverse
|
86
|
+
engineering for debugging such modifications, if you also do each of
|
87
|
+
the following:
|
88
|
+
|
89
|
+
a) Give prominent notice with each copy of the Combined Work that
|
90
|
+
the Library is used in it and that the Library and its use are
|
91
|
+
covered by this License.
|
92
|
+
|
93
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
94
|
+
document.
|
95
|
+
|
96
|
+
c) For a Combined Work that displays copyright notices during
|
97
|
+
execution, include the copyright notice for the Library among
|
98
|
+
these notices, as well as a reference directing the user to the
|
99
|
+
copies of the GNU GPL and this license document.
|
100
|
+
|
101
|
+
d) Do one of the following:
|
102
|
+
|
103
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
104
|
+
License, and the Corresponding Application Code in a form
|
105
|
+
suitable for, and under terms that permit, the user to
|
106
|
+
recombine or relink the Application with a modified version of
|
107
|
+
the Linked Version to produce a modified Combined Work, in the
|
108
|
+
manner specified by section 6 of the GNU GPL for conveying
|
109
|
+
Corresponding Source.
|
110
|
+
|
111
|
+
1) Use a suitable shared library mechanism for linking with the
|
112
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
113
|
+
a copy of the Library already present on the user's computer
|
114
|
+
system, and (b) will operate properly with a modified version
|
115
|
+
of the Library that is interface-compatible with the Linked
|
116
|
+
Version.
|
117
|
+
|
118
|
+
e) Provide Installation Information, but only if you would otherwise
|
119
|
+
be required to provide such information under section 6 of the
|
120
|
+
GNU GPL, and only to the extent that such information is
|
121
|
+
necessary to install and execute a modified version of the
|
122
|
+
Combined Work produced by recombining or relinking the
|
123
|
+
Application with a modified version of the Linked Version. (If
|
124
|
+
you use option 4d0, the Installation Information must accompany
|
125
|
+
the Minimal Corresponding Source and Corresponding Application
|
126
|
+
Code. If you use option 4d1, you must provide the Installation
|
127
|
+
Information in the manner specified by section 6 of the GNU GPL
|
128
|
+
for conveying Corresponding Source.)
|
129
|
+
|
130
|
+
5. Combined Libraries.
|
131
|
+
|
132
|
+
You may place library facilities that are a work based on the
|
133
|
+
Library side by side in a single library together with other library
|
134
|
+
facilities that are not Applications and are not covered by this
|
135
|
+
License, and convey such a combined library under terms of your
|
136
|
+
choice, if you do both of the following:
|
137
|
+
|
138
|
+
a) Accompany the combined library with a copy of the same work based
|
139
|
+
on the Library, uncombined with any other library facilities,
|
140
|
+
conveyed under the terms of this License.
|
141
|
+
|
142
|
+
b) Give prominent notice with the combined library that part of it
|
143
|
+
is a work based on the Library, and explaining where to find the
|
144
|
+
accompanying uncombined form of the same work.
|
145
|
+
|
146
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
147
|
+
|
148
|
+
The Free Software Foundation may publish revised and/or new versions
|
149
|
+
of the GNU Lesser General Public License from time to time. Such new
|
150
|
+
versions will be similar in spirit to the present version, but may
|
151
|
+
differ in detail to address new problems or concerns.
|
152
|
+
|
153
|
+
Each version is given a distinguishing version number. If the
|
154
|
+
Library as you received it specifies that a certain numbered version
|
155
|
+
of the GNU Lesser General Public License "or any later version"
|
156
|
+
applies to it, you have the option of following the terms and
|
157
|
+
conditions either of that published version or of any later version
|
158
|
+
published by the Free Software Foundation. If the Library as you
|
159
|
+
received it does not specify a version number of the GNU Lesser
|
160
|
+
General Public License, you may choose any version of the GNU Lesser
|
161
|
+
General Public License ever published by the Free Software Foundation.
|
162
|
+
|
163
|
+
If the Library as you received it specifies that a proxy can decide
|
164
|
+
whether future versions of the GNU Lesser General Public License shall
|
165
|
+
apply, that proxy's public statement of acceptance of any version is
|
166
|
+
permanent authorization for you to choose that version for the
|
167
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
beid_parser
|
2
|
+
===========
|
3
|
+
Ruby beID parser. Allowing to easily handle beID xml files
|
4
|
+
|
5
|
+
Please refer to http://eid.belgium.be/en/developing_eid_applications/ for references
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
**Create a new Beid from a beID xml file:**
|
10
|
+
- beid = BeidParser::Beid.new(filepath)
|
11
|
+
|
12
|
+
**Methods accessibles:**
|
13
|
+
- #picture64: The picture encoded in base64
|
14
|
+
- #picture: The decoded picture
|
15
|
+
- #extract_picture([filename]): Write the JPG picture into a file
|
16
|
+
- #name: The family name
|
17
|
+
- #firstname The firstname (including second first name if any)
|
18
|
+
- #firstnames: Array of firstnames
|
19
|
+
- #middlename: The middlename
|
20
|
+
- #nationality: The nationality
|
21
|
+
- #place_of_birth: The place of birth
|
22
|
+
- #date_of_birth: The date of birth, *Date*
|
23
|
+
- #national_number: The national number, *Fixnum*
|
24
|
+
- #gender: The gender ("male" or "female")
|
25
|
+
- #validity_date_begin: The card validity begin date, *Date*
|
26
|
+
- #validity_date_end: The card validity end date, *Date*
|
27
|
+
- #delivery_municipality: The delivery municipality
|
28
|
+
- #street_and_number: The street and number of the citizen address
|
29
|
+
- #zip: The zip code of the citizen address, *Fixnum*
|
30
|
+
- #municipality: The municipality of the citizen address
|
31
|
+
- #document_type: The document type (belgian_citizen,...)
|
32
|
+
- #card_number: The card number, *Fixnum*
|
33
|
+
- #chip_number: The chip number
|
34
|
+
- #certificates: A Hash of all the certificates on the card (typically :root,:citizenca,:authentication,:signing,rrn)
|
35
|
+
|
36
|
+
NB: When not specified fields are stored as String.
|
data/Rakefile
ADDED
data/lib/beid_parser.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
class BeidParser::Beid
|
2
|
+
include REXML
|
3
|
+
attr_reader :picture64,:name,:firstname,:middlename,
|
4
|
+
:nationality,:place_of_birth,:date_of_birth,:national_number, :gender,:document_type,
|
5
|
+
:card_number,:chip_number,:validity_date_begin,:validity_date_end,
|
6
|
+
:delivery_municipality,:street_and_number,:zip,:municipality,
|
7
|
+
:certificates
|
8
|
+
def initialize(filename)
|
9
|
+
@document = Document.new(File.new(filename))
|
10
|
+
parse_document
|
11
|
+
end
|
12
|
+
|
13
|
+
#Return an array of firstnames
|
14
|
+
def firstnames
|
15
|
+
firstname.split(" ")
|
16
|
+
end
|
17
|
+
|
18
|
+
# Decode the Base64 encoded picture
|
19
|
+
def picture
|
20
|
+
Base64.decode64(picture64)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Extract the citizen picture into a JPG file
|
24
|
+
def extract_picture(filename="picture.jpg")
|
25
|
+
if !filename.match(/.*\.jpg/)
|
26
|
+
raise "The ouput file for the picture must have the '.jpg' extension."
|
27
|
+
end
|
28
|
+
|
29
|
+
File.open(filename, 'w') { |f| f.write(picture) }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
# Extract datas from XML
|
34
|
+
def parse_document
|
35
|
+
root = @document.root
|
36
|
+
identity = root.elements.to_a("identity").first
|
37
|
+
card = root.elements.to_a("card").first
|
38
|
+
address = root.elements.to_a("address").first
|
39
|
+
xml_certificates = root.elements.to_a("certificates").first
|
40
|
+
|
41
|
+
# Identity
|
42
|
+
@national_number = get_info(identity, "nationalnumber", true).to_i
|
43
|
+
@date_of_birth = parse_date(get_info(identity, "dateofbirth", true))
|
44
|
+
@gender = get_info(identity, "gender", true)
|
45
|
+
@name = get_info(identity, "name")
|
46
|
+
@firstname = get_info(identity, "firstname")
|
47
|
+
@middlename = get_info(identity, "middlename")
|
48
|
+
@nationality = get_info(identity, "nationality")
|
49
|
+
@place_of_birth = get_info(identity, "placeofbirth")
|
50
|
+
@picture64 = get_info(identity, "photo")
|
51
|
+
|
52
|
+
# Card
|
53
|
+
@document_type = get_info(card, "documenttype", true)
|
54
|
+
@card_number = get_info(card, "cardnumber", true).to_i
|
55
|
+
@chip_number = get_info(card, "chipnumber", true)
|
56
|
+
@validity_date_begin = parse_date(get_info(card,"validitydatebegin",true))
|
57
|
+
@validity_date_end = parse_date(get_info(card,"validitydateend",true))
|
58
|
+
@delivery_municipality = get_info(card, "deliverymunicipality")
|
59
|
+
|
60
|
+
# Address
|
61
|
+
@street_and_number = get_info(address, "streetandnumber")
|
62
|
+
@zip = get_info(address, "zip").to_i
|
63
|
+
@municipality = get_info(address, "municipality")
|
64
|
+
|
65
|
+
# Certificates
|
66
|
+
@certificates = {}
|
67
|
+
xml_certificates.elements.each do |e|
|
68
|
+
@certificates[e.name] = get_info(xml_certificates,e.name)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
# Get info from the XML element attributes or children
|
74
|
+
def get_info(element,key,attrib=false)
|
75
|
+
if attrib
|
76
|
+
element.attributes[key]
|
77
|
+
else
|
78
|
+
element.elements.to_a(key).first.text
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Return a Date object from a string of pattern YYYYMMDD
|
83
|
+
def parse_date(date)
|
84
|
+
Date.new(date[0..3].to_i,date[4..5].to_i,date[6..7].to_i)
|
85
|
+
end
|
86
|
+
end
|
data/spec/beid_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beid_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thibault Poncelet
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-04-21 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.5"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Ruby beID parser. Allowing to easily handle beID xml files
|
27
|
+
email: thibaultponcelet@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- lib/beid_parser/beid.rb
|
36
|
+
- lib/beid_parser/version.rb
|
37
|
+
- lib/beid_parser.rb
|
38
|
+
- LICENSE
|
39
|
+
- Rakefile
|
40
|
+
- README.md
|
41
|
+
- spec/beid_spec.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
homepage: https://github.com/thibaultponcelet/beid_parser
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.9.2
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.17
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Ruby beID parser. Allowing to easily handle beID xml files
|
70
|
+
test_files:
|
71
|
+
- spec/beid_spec.rb
|
72
|
+
- spec/spec_helper.rb
|