ig3tool 0.3.0 → 0.4.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.
- data/bin/ig3tool +1 -1
- data/lib/glade/sales.glade +84 -84
- data/lib/ui/{internewindow.rb → OLD_internewindow.rb} +0 -0
- data/lib/ui/{memberswindow.rb → OLD_memberswindow.rb} +0 -0
- data/lib/ui/{productswindow.rb → OLD_productswindow.rb} +0 -0
- data/lib/ui/gladehelper.rb +3 -2
- data/lib/ui/{newinterne.rb → interne.rb} +2 -1
- data/lib/ui/peoplewindow.rb +1 -1
- data/lib/ui/printingwindow.rb +6 -6
- data/lib/ui/protjes.rb +6 -0
- data/lib/ui/saleswindow.rb +72 -25
- data/lib/ui/toolwindow.rb +3 -3
- metadata +70 -95
- data/lib/actions/bib.rb +0 -295
- data/lib/actions/bitching.rb +0 -19
- data/lib/actions/cultuur.rb +0 -3
- data/lib/actions/interne.rb +0 -98
- data/lib/actions/kaching.rb +0 -90
- data/lib/actions/people.rb +0 -178
- data/lib/actions/printing.rb +0 -125
- data/lib/actions/product.rb +0 -154
- data/lib/bib.rb +0 -94
- data/lib/billing.rb +0 -112
- data/lib/bitching.rb +0 -49
- data/lib/config.rb +0 -19
- data/lib/horrible_hack.rb +0 -15
- data/lib/interne.rb +0 -111
- data/lib/ldap.rb +0 -104
- data/lib/log.rb +0 -25
- data/lib/membership.rb +0 -32
- data/lib/mymd5.rb +0 -95
- data/lib/people.rb +0 -143
- data/lib/printing.rb +0 -238
- data/lib/request.rb +0 -14
- data/lib/sales.rb +0 -158
- data/lib/utils.rb +0 -106
- data/lib/web.rb +0 -98
data/lib/ui/toolwindow.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ig3tool
|
2
2
|
|
3
|
-
require 'pathname'
|
3
|
+
require 'pathname'
|
4
4
|
|
5
5
|
# Hoofdmenu (altijd on top)
|
6
6
|
# Zorgt voor dynamische uitbreidingsmogelijkheden van de ig3tool
|
@@ -14,13 +14,13 @@ module Ig3tool
|
|
14
14
|
def initialize (klasses)
|
15
15
|
window = Gtk::Window.new
|
16
16
|
window.title = "Ig3tool"
|
17
|
-
window.type_hint = Gdk::Window::
|
17
|
+
window.type_hint = Gdk::Window::TYPE_HINT_NORMAL
|
18
18
|
#window.keep_above = true
|
19
19
|
window.move(0,0)
|
20
20
|
|
21
21
|
bigbox = Gtk::VBox.new(true)
|
22
22
|
bigbox.border_width = 6
|
23
|
-
bigbox.spacing = 12
|
23
|
+
bigbox.spacing = 12
|
24
24
|
window.add(bigbox)
|
25
25
|
|
26
26
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ig3tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Pinte
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-04-01 00:00:00 +02:00
|
13
13
|
default_executable: ig3tool
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,120 +30,95 @@ extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
31
31
|
|
32
32
|
files:
|
33
|
-
- lib/actions
|
34
|
-
- lib/bib.rb
|
35
|
-
- lib/billing.rb
|
36
|
-
- lib/bitching.rb
|
37
|
-
- lib/config.rb
|
38
|
-
- lib/glade
|
39
|
-
- lib/horrible_hack.rb
|
40
|
-
- lib/interne.rb
|
41
|
-
- lib/ldap.rb
|
42
|
-
- lib/lib
|
43
|
-
- lib/log.rb
|
44
|
-
- lib/membership.rb
|
45
|
-
- lib/mymd5.rb
|
46
|
-
- lib/people.rb
|
47
|
-
- lib/printing.rb
|
48
|
-
- lib/request.rb
|
49
|
-
- lib/sales.rb
|
50
33
|
- lib/ui
|
51
|
-
- lib/
|
52
|
-
- lib/
|
34
|
+
- lib/lib
|
35
|
+
- lib/glade
|
53
36
|
- bin/ig3tool
|
54
|
-
- lib/
|
55
|
-
- lib/
|
56
|
-
- lib/
|
57
|
-
- lib/
|
58
|
-
- lib/
|
59
|
-
- lib/
|
60
|
-
- lib/
|
61
|
-
- lib/
|
62
|
-
- lib/
|
37
|
+
- lib/ui/OLD_internewindow.rb
|
38
|
+
- lib/ui/OLD_memberswindow.rb
|
39
|
+
- lib/ui/bibwindow.rb
|
40
|
+
- lib/ui/loginwindow.rb
|
41
|
+
- lib/ui/toolwindow.rb
|
42
|
+
- lib/ui/saleswindow.rb
|
43
|
+
- lib/ui/printingwindow.rb
|
44
|
+
- lib/ui/OLD_productswindow.rb
|
45
|
+
- lib/ui/automaatwindow.rb
|
46
|
+
- lib/ui/peoplewindow.rb
|
47
|
+
- lib/ui/protjes.rb
|
48
|
+
- lib/ui/messagebox.rb
|
49
|
+
- lib/ui/gladehelper.rb
|
50
|
+
- lib/ui/bibliotheekwindow.rb
|
51
|
+
- lib/ui/OLD_printenwindow.rb
|
52
|
+
- lib/ui/interne.rb
|
53
|
+
- lib/lib/errors.rb
|
54
|
+
- lib/lib/util.rb
|
55
|
+
- lib/glade/stock_bookmark_klein.png
|
56
|
+
- lib/glade/protjes.glade
|
57
|
+
- lib/glade/printing.glade
|
58
|
+
- lib/glade/penningtool.glade
|
63
59
|
- lib/glade/bibliotheek.glade
|
64
|
-
- lib/glade/
|
65
|
-
- lib/glade/
|
60
|
+
- lib/glade/products.glade
|
61
|
+
- lib/glade/vendingmachine.glade
|
62
|
+
- lib/glade/stock_print.png
|
63
|
+
- lib/glade/members.svg
|
64
|
+
- lib/glade/printerlog_klein.png
|
65
|
+
- lib/glade/bib.glade
|
66
|
+
- lib/glade/memberinfo.svg
|
66
67
|
- lib/glade/cola_small.png
|
67
|
-
- lib/glade/
|
68
|
-
- lib/glade/
|
69
|
-
- lib/glade/
|
68
|
+
- lib/glade/members_xklein.png
|
69
|
+
- lib/glade/printer_klein.png
|
70
|
+
- lib/glade/printer.png
|
71
|
+
- lib/glade/loginwindow.glade
|
72
|
+
- lib/glade/printen.glade
|
70
73
|
- lib/glade/icons
|
71
|
-
- lib/glade/icons/
|
72
|
-
- lib/glade/icons/
|
73
|
-
- lib/glade/icons/
|
74
|
+
- lib/glade/icons/stock_bookmark_klein.png
|
75
|
+
- lib/glade/icons/emblem-penning.xpm
|
76
|
+
- lib/glade/icons/stock_print.png
|
77
|
+
- lib/glade/icons/emblem-money.png
|
78
|
+
- lib/glade/icons/no.xpm
|
74
79
|
- lib/glade/icons/cola_small.png
|
80
|
+
- lib/glade/icons/members_xklein.png
|
81
|
+
- lib/glade/icons/cola.png
|
82
|
+
- lib/glade/icons/stock_book_xklein.png
|
83
|
+
- lib/glade/icons/stock_bookmark.svg
|
75
84
|
- lib/glade/icons/cola_xsmall.png
|
76
|
-
- lib/glade/icons/
|
85
|
+
- lib/glade/icons/piggy_small.png
|
77
86
|
- lib/glade/icons/doos_xsmall.png
|
78
|
-
- lib/glade/icons/
|
87
|
+
- lib/glade/icons/cola_light_xsmall.png
|
88
|
+
- lib/glade/icons/stock_book.svg
|
89
|
+
- lib/glade/icons/gdict.png
|
79
90
|
- lib/glade/icons/emblem-package.png
|
80
|
-
- lib/glade/icons/
|
91
|
+
- lib/glade/icons/stock_book_klein.png
|
81
92
|
- lib/glade/icons/emblem-people.png
|
93
|
+
- lib/glade/icons/stock_bookmark_xklein.png
|
94
|
+
- lib/glade/icons/doos_small.png
|
82
95
|
- lib/glade/icons/emblem-sales.png
|
83
|
-
- lib/glade/icons/gdict.png
|
84
96
|
- lib/glade/icons/members_klein.png
|
85
|
-
- lib/glade/icons/members_xklein.png
|
86
|
-
- lib/glade/icons/no.xpm
|
87
|
-
- lib/glade/icons/piggy_small.png
|
88
97
|
- lib/glade/icons/piggy_xsmall.png
|
89
|
-
- lib/glade/icons/
|
90
|
-
- lib/glade/icons/stock_book_klein.png
|
91
|
-
- lib/glade/icons/stock_book_xklein.png
|
92
|
-
- lib/glade/icons/stock_bookmark.svg
|
93
|
-
- lib/glade/icons/stock_bookmark_klein.png
|
94
|
-
- lib/glade/icons/stock_bookmark_xklein.png
|
95
|
-
- lib/glade/icons/stock_print.png
|
98
|
+
- lib/glade/icons/cola_light_small.png
|
96
99
|
- lib/glade/interne.glade
|
97
|
-
- lib/glade/
|
98
|
-
- lib/glade/memberinfo.svg
|
99
|
-
- lib/glade/memberinfo_klein.png
|
100
|
-
- lib/glade/memberinfo_xklein.png
|
100
|
+
- lib/glade/money_xsmall.png
|
101
101
|
- lib/glade/members.glade
|
102
|
-
- lib/glade/
|
103
|
-
- lib/glade/
|
104
|
-
- lib/glade/
|
102
|
+
- lib/glade/printerlog_xklein.png
|
103
|
+
- lib/glade/stock_book_xklein.png
|
104
|
+
- lib/glade/cola_xsmall.png
|
105
|
+
- lib/glade/piggy_small.png
|
105
106
|
- lib/glade/money_small.png
|
106
|
-
- lib/glade/money_xsmall.png
|
107
107
|
- lib/glade/newinterne.glade
|
108
|
-
- lib/glade/
|
109
|
-
- lib/glade/people.glade
|
110
|
-
- lib/glade/piggy_small.png
|
111
|
-
- lib/glade/piggy_xsmall.png
|
112
|
-
- lib/glade/printen.glade
|
113
|
-
- lib/glade/printer.png
|
114
|
-
- lib/glade/printer_klein.png
|
115
|
-
- lib/glade/printer_xklein.png
|
116
|
-
- lib/glade/printerlog_klein.png
|
117
|
-
- lib/glade/printerlog_xklein.png
|
118
|
-
- lib/glade/printing.glade
|
119
|
-
- lib/glade/products.glade
|
120
|
-
- lib/glade/protjes.glade
|
108
|
+
- lib/glade/doos_xsmall.png
|
121
109
|
- lib/glade/sales.glade
|
110
|
+
- lib/glade/cola_light_xsmall.png
|
122
111
|
- lib/glade/stock_book.svg
|
112
|
+
- lib/glade/memberinfo_xklein.png
|
113
|
+
- lib/glade/people.glade
|
123
114
|
- lib/glade/stock_book_klein.png
|
124
|
-
- lib/glade/stock_book_xklein.png
|
125
|
-
- lib/glade/stock_bookmark_klein.png
|
126
115
|
- lib/glade/stock_bookmark_xklein.png
|
127
|
-
- lib/glade/
|
128
|
-
- lib/glade/
|
129
|
-
- lib/
|
130
|
-
- lib/
|
131
|
-
- lib/
|
132
|
-
- lib/
|
133
|
-
- lib/ui/bibwindow.rb
|
134
|
-
- lib/ui/gladehelper.rb
|
135
|
-
- lib/ui/internewindow.rb
|
136
|
-
- lib/ui/loginwindow.rb
|
137
|
-
- lib/ui/memberswindow.rb
|
138
|
-
- lib/ui/messagebox.rb
|
139
|
-
- lib/ui/newinterne.rb
|
140
|
-
- lib/ui/OLD_printenwindow.rb
|
141
|
-
- lib/ui/peoplewindow.rb
|
142
|
-
- lib/ui/printingwindow.rb
|
143
|
-
- lib/ui/productswindow.rb
|
144
|
-
- lib/ui/protjes.rb
|
145
|
-
- lib/ui/saleswindow.rb
|
146
|
-
- lib/ui/toolwindow.rb
|
116
|
+
- lib/glade/memberinfo_klein.png
|
117
|
+
- lib/glade/doos_small.png
|
118
|
+
- lib/glade/members_klein.png
|
119
|
+
- lib/glade/piggy_xsmall.png
|
120
|
+
- lib/glade/cola_light_small.png
|
121
|
+
- lib/glade/printer_xklein.png
|
147
122
|
has_rdoc: false
|
148
123
|
homepage: http://infogroep.be
|
149
124
|
post_install_message:
|
data/lib/actions/bib.rb
DELETED
@@ -1,295 +0,0 @@
|
|
1
|
-
module Ig3tool
|
2
|
-
class Actions
|
3
|
-
|
4
|
-
# Geeft alle secties terug die in de bib te vinden zijn.
|
5
|
-
def self.bib_sections(params)
|
6
|
-
BibSection.find(:all, :order => "name")
|
7
|
-
end
|
8
|
-
|
9
|
-
# Geeft een lijst van boeken terug.
|
10
|
-
# Geen params -> alle boeken
|
11
|
-
# ALL UPPERCASE -> alle boeken in die sectie
|
12
|
-
# else -> zoek in titels en auteurs
|
13
|
-
def self.bib_books(params)
|
14
|
-
p = params[:from_uri].first
|
15
|
-
if p.nil? || p.empty? then
|
16
|
-
BibBook.find(:all, :order => "title")
|
17
|
-
elsif p =~ /^(\d|X){10,}/ # Indien hij begint met X of een digit -> ISBN
|
18
|
-
BibBook.find(_isbn(p))
|
19
|
-
elsif p == p.upcase # Indien in uppercase -> Section
|
20
|
-
BibSection.find(p).books
|
21
|
-
else
|
22
|
-
p = '%' + p + '%'
|
23
|
-
BibBook.find(:all, :order => "title", :conditions => [ "title like ? or author like ?", p, p ])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Geeft alle info over een boek terug
|
28
|
-
# Verwacht een ISBN
|
29
|
-
def self.bib_info(params)
|
30
|
-
raise Needed, "barcode" if params[:given_uri] != 1
|
31
|
-
isbn = _isbn(params[:from_uri].first) or raise InvalidISBN, "Invalid isbn number"
|
32
|
-
BibBook.find_by_isbn isbn # Return een boek
|
33
|
-
end
|
34
|
-
|
35
|
-
# Geeft alle uitgeleende boeken terug
|
36
|
-
# Verwacht geen parameters
|
37
|
-
def self.bib_loans(params)
|
38
|
-
if params[:given_uri] == 1
|
39
|
-
memberid = params[:from_uri].first
|
40
|
-
BibLoan.find_by_member_id(memberid)
|
41
|
-
else
|
42
|
-
BibLoan.find(:all, :order => "return_date ASC")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Kijkt of een bepaald boek url[0] beschikbaar is
|
47
|
-
def self.bib_availableinfo(params)
|
48
|
-
raise Needed, "barcode" if params[:given_uri] != 1
|
49
|
-
isbn = _isbn(params[:from_uri].first)
|
50
|
-
_available(isbn,true)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Kijkt of een bepaald boek url[0] beschikbaar is
|
54
|
-
def self.bib_available(params)
|
55
|
-
raise Needed, "barcode" if params[:given_uri] != 1
|
56
|
-
isbn = _isbn(params[:from_uri].first) or raise InvalidISBN, "Invalid isbn number"
|
57
|
-
_available(isbn)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Vernietigt de lening van het gegeven 'isbn' en 'member'
|
61
|
-
def self.bib_return!(params)
|
62
|
-
isbn = _isbn(params["isbn"]) or raise InvalidISBN, "Invalid isbn number"
|
63
|
-
member = params["member"] or raise Needed, "membership"
|
64
|
-
name = Membership.find(member).username
|
65
|
-
book = BibBook.find(isbn)
|
66
|
-
l = BibLoan.find(:all, :conditions =>
|
67
|
-
[ "member_id = ? and isbn = ?", member, isbn ])
|
68
|
-
if l.empty?
|
69
|
-
raise NotFound, "Book #{isbn} not loaned by #{name}" if loan.nil?
|
70
|
-
else
|
71
|
-
Logger::log :bib, :return, "%s returned %s (%s)" %
|
72
|
-
[ name, isbn, book.title ]
|
73
|
-
|
74
|
-
l.first.destroy
|
75
|
-
"OK"
|
76
|
-
end
|
77
|
-
rescue ActiveRecord::RecordNotFound
|
78
|
-
raise NotAMember, params['member']
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.bib_lookup(params)
|
82
|
-
raise Needed, "search value" if params[:given_uri] == 0
|
83
|
-
raise Needed, "even number of values" if params[:given_uri] % 2 == 1
|
84
|
-
|
85
|
-
valid_keys = %w(title author publisher year section copies isbn)
|
86
|
-
h = params[:from_uri].to_h
|
87
|
-
h["isbn"] = _isbn(h["isbn"]) unless h["isbn"].nil?
|
88
|
-
BibBook.hash_lookup(h, valid_keys)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Maakt een lening aan voor het gegeven 'isbn' voor 'member' met 'warranty'.
|
92
|
-
# Standaard datum van teruggave is nu+3 weken,
|
93
|
-
# standaard garantie is "debugger ? 0 : 5"
|
94
|
-
def self.bib_loan!(params)
|
95
|
-
isbn = _isbn(params["isbn"]) or raise InvalidISBN, "Invalid isbn number"
|
96
|
-
book = BibBook.find(isbn)
|
97
|
-
|
98
|
-
raise BookNotAvaible, "All copies loaned out!" unless book.available?
|
99
|
-
|
100
|
-
member = Membership.find params["member"]
|
101
|
-
raise NotAMember, params["member"] if member.nil?
|
102
|
-
|
103
|
-
warranty = params["warranty"] || (member.debugger? ? 0 : 5)
|
104
|
-
loan_date = Time.now
|
105
|
-
return_date = Time.now + 3.weeks
|
106
|
-
|
107
|
-
BibLoan.create(:isbn => book.isbn,
|
108
|
-
:member_id => member.barcode,
|
109
|
-
:warranty => warranty,
|
110
|
-
:loan_date => loan_date,
|
111
|
-
:return_date => return_date)
|
112
|
-
|
113
|
-
Logger::log :bib, :loan, "%s loaned %s (%s)." %
|
114
|
-
[ member.person.username, isbn, book.title ]
|
115
|
-
|
116
|
-
"OK"
|
117
|
-
end
|
118
|
-
|
119
|
-
# Verleng een lening voor het gegeven 'isbn' voor 'member'.
|
120
|
-
def self.bib_extend!(params)
|
121
|
-
isbn = _isbn(params["isbn"]) or raise InvalidISBN, "Invalid isbn number"
|
122
|
-
|
123
|
-
member = Membership.find params["member"]
|
124
|
-
raise NotAMember, params["member"] if member.nil?
|
125
|
-
|
126
|
-
book = BibBook.find(isbn)
|
127
|
-
loan = BibLoan.find_by_isbn_and_member_id(book.isbn, member.barcode)
|
128
|
-
return_date = Time.parse(loan.return_date) + 3.weeks
|
129
|
-
#return_date = Time.now + 3.weeks
|
130
|
-
#
|
131
|
-
loan.return_date = return_date
|
132
|
-
loan.save!
|
133
|
-
|
134
|
-
Logger::log :bib, :loan, "%s extended %s (%s)." %
|
135
|
-
[ member.person.username, isbn, book.title ]
|
136
|
-
|
137
|
-
loan # Return Loan
|
138
|
-
end
|
139
|
-
|
140
|
-
# Een boek aanmaken. Verwacht "isbn", "title", "author", "publisher", "year".
|
141
|
-
# Mogelijkheid om "copies" ook bij te zetten, default 1.
|
142
|
-
# Returnt het ISBN van het nieuwe boek.
|
143
|
-
def self.bib_add!(params)
|
144
|
-
notfound = []
|
145
|
-
[:isbn, :title, :author, :publisher, :year].each do |k|
|
146
|
-
notfound << k if params[k.to_s].nil?
|
147
|
-
end
|
148
|
-
|
149
|
-
raise Needed, notfound unless notfound.empty?
|
150
|
-
isbn = _isbn(params["isbn"]) or raise InvalidISBN, "Invalid isbn number"
|
151
|
-
|
152
|
-
b = BibBook.find_by_isbn(isbn)
|
153
|
-
|
154
|
-
unless b.nil?
|
155
|
-
b.title = params["title"]
|
156
|
-
b.author = params["author"]
|
157
|
-
b.publisher = params["publisher"]
|
158
|
-
b.year = params["year"]
|
159
|
-
b.section = params["section"]
|
160
|
-
b.copies = params["copies"] || 1
|
161
|
-
b.save # DB Save
|
162
|
-
|
163
|
-
Logger::log :bib, :update, "Book %s (%s) updated." %
|
164
|
-
[ params["isbn"], params["title"] ]
|
165
|
-
|
166
|
-
else
|
167
|
-
b = BibBook.new(:isbn => isbn,
|
168
|
-
:title => params["title"],
|
169
|
-
:author => params["author"],
|
170
|
-
:publisher => params["publisher"],
|
171
|
-
:year => params["year"],
|
172
|
-
:section => params["section"],
|
173
|
-
:copies => params["copies"] || 1)
|
174
|
-
|
175
|
-
b.save!
|
176
|
-
|
177
|
-
Logger::log :bib, :add, "Book %s (%s) created." %
|
178
|
-
[ isbn, params["title"] ]
|
179
|
-
end
|
180
|
-
|
181
|
-
b.isbn
|
182
|
-
|
183
|
-
rescue ActiveRecord::RecordInvalid
|
184
|
-
raise BibSectionNotFound, "the ig3tool imps want you to select a section..."
|
185
|
-
end
|
186
|
-
|
187
|
-
# Een boek verwijderen, verwacht het ISBN nummer in :isbn.
|
188
|
-
def self.bib_remove!(params)
|
189
|
-
isbn = _isbn(params["isbn"]) or raise InvalidISBN, "Invalid isbn number"
|
190
|
-
book = BibBook.find(isbn)
|
191
|
-
raise BookNotAvaible, "Book is loaned" unless book.loans.empty?
|
192
|
-
|
193
|
-
book.destroy
|
194
|
-
|
195
|
-
Logger::log :bib, :remove, "Book %d removed." % params["isbn"]
|
196
|
-
|
197
|
-
"OK"
|
198
|
-
rescue ActiveRecord::RecordNotFound
|
199
|
-
raise NotFound, "book"
|
200
|
-
end
|
201
|
-
|
202
|
-
private
|
203
|
-
# Kijk of een bepaald boek nog beschikbaar is
|
204
|
-
def self._available(isbn,extra_info = false)
|
205
|
-
begin
|
206
|
-
begin
|
207
|
-
b = BibBook.find(isbn)
|
208
|
-
rescue ActiveRecord::RecordNotFound
|
209
|
-
b = BibBook.find(_isbn(isbn))
|
210
|
-
end
|
211
|
-
|
212
|
-
|
213
|
-
if extra_info
|
214
|
-
{ "copies" => b.copies, "loans" => b.loans.length }
|
215
|
-
else
|
216
|
-
b.available?
|
217
|
-
end
|
218
|
-
rescue ActiveRecord::RecordNotFound
|
219
|
-
raise NotFound, "the ig3tool imps found no such book..."
|
220
|
-
end
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
# Controleert op de geldigheid van een isbn nummer
|
225
|
-
# isbn nummers die beginnen met IG0 zijn gevrijwaard van de controle
|
226
|
-
# en dienen voor zelfgemaakte barcode
|
227
|
-
def self._isbn (code, strong_check = false)
|
228
|
-
code = code.to_s.gsub(/\W/, '')
|
229
|
-
raise Needed, "ISBN" if code.nil? or code.empty?
|
230
|
-
|
231
|
-
if !strong_check and code =~ /^IG0/ # Indien zelfgemaakte barcode
|
232
|
-
return code
|
233
|
-
|
234
|
-
# indien oude isbn (10 cijfers)
|
235
|
-
elsif code.length == 10
|
236
|
-
code = code.gsub(/[^0-9Xx]+/, '').tr('x', 'X')
|
237
|
-
|
238
|
-
sum = 0
|
239
|
-
9.times {|i| sum += code[i].chr.to_i * (10 - i) }
|
240
|
-
sum += if code =~ /X$/ then 10 else code[9].chr.to_i end
|
241
|
-
|
242
|
-
# geldige barcode, converten naar 13
|
243
|
-
if sum % 11 == 0
|
244
|
-
return BibBook._isbn13(code)
|
245
|
-
end
|
246
|
-
|
247
|
-
# indien nieuwe isbn (13 cijfers - jan 2007)
|
248
|
-
elsif code.length == 13
|
249
|
-
sum = 0
|
250
|
-
multiply = 1
|
251
|
-
0.upto(11){|i|
|
252
|
-
sum += code[i].chr.to_i * multiply
|
253
|
-
if multiply == 1 then multiply = 3 else multiply = 1 end
|
254
|
-
}
|
255
|
-
|
256
|
-
return code if code[12].chr.to_i == (10 - (sum % 10))
|
257
|
-
end
|
258
|
-
|
259
|
-
# geen geldig isbn
|
260
|
-
return nil
|
261
|
-
end
|
262
|
-
|
263
|
-
# XXX move naar util.rb?
|
264
|
-
# Convert ISBN10 naar ISBN13
|
265
|
-
def self._isbn13(code)
|
266
|
-
raise InvalidISBN if code.length != 10
|
267
|
-
code.chop!
|
268
|
-
code = "978" + code
|
269
|
-
|
270
|
-
sum = 0
|
271
|
-
code.split(//).each_with_index do |c, i|
|
272
|
-
sum += c.to_i * ( i % 2 == 0 ? 1 : 3 )
|
273
|
-
end
|
274
|
-
|
275
|
-
rem = sum % 10
|
276
|
-
check = (rem == 0) ? 0 : 10 - rem
|
277
|
-
|
278
|
-
code = code + check.to_s
|
279
|
-
end
|
280
|
-
|
281
|
-
# Convert ISBN13 naar ISBN10
|
282
|
-
def self._isbn10(code)
|
283
|
-
raise InvalidISBN if code.length != 13
|
284
|
-
code = code[3..11]
|
285
|
-
|
286
|
-
sum = 0
|
287
|
-
9.times {|i| sum += code[i].chr.to_i * (10 - i) }
|
288
|
-
|
289
|
-
check = 11 - sum % 11
|
290
|
-
check = 0 if sum == 0
|
291
|
-
check = 'X' if check == 10
|
292
|
-
code = code + check.to_s
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|