sip2 0.1.1 → 0.2.4

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.
@@ -1,200 +0,0 @@
1
- module Sip2
2
- #
3
- # Sip2 Patron Information
4
- #
5
- class PatronInformation
6
- attr_reader :raw_response
7
-
8
- def initialize(patron_response)
9
- @raw_response = patron_response
10
- end
11
-
12
- def charge_privileges_denied?
13
- parse_patron_status 0
14
- end
15
-
16
- def renewal_privileges_denied?
17
- parse_patron_status 1
18
- end
19
-
20
- def recall_privileges_denied?
21
- parse_patron_status 2
22
- end
23
-
24
- def hold_privileges_denied?
25
- parse_patron_status 3
26
- end
27
-
28
- def card_reported_lost?
29
- parse_patron_status 4
30
- end
31
-
32
- def too_many_items_charged?
33
- parse_patron_status 5
34
- end
35
-
36
- def too_many_items_overdue?
37
- parse_patron_status 6
38
- end
39
-
40
- def too_many_renewals?
41
- parse_patron_status 7
42
- end
43
-
44
- def too_many_claims_of_items_returned?
45
- parse_patron_status 8
46
- end
47
-
48
- def too_many_items_lost?
49
- parse_patron_status 9
50
- end
51
-
52
- def excessive_outstanding_fines?
53
- parse_patron_status 10
54
- end
55
-
56
- def excessive_outstanding_fees?
57
- parse_patron_status 11
58
- end
59
-
60
- def recall_overdue?
61
- parse_patron_status 12
62
- end
63
-
64
- def too_many_items_billed?
65
- parse_patron_status 13
66
- end
67
-
68
- def language
69
- LANGUAGE_LOOKUP_TABLE[parse_fixed_response(14, 3)]
70
- end
71
-
72
- def transaction_date
73
- match = raw_response.match(/\A64.{17}(\d{4})(\d{2})(\d{2})(.{4})(\d{2})(\d{2})(\d{2})/)
74
- return unless match
75
-
76
- _, year, month, day, zone, hour, minute, second = match.to_a
77
- Time.new(
78
- year.to_i, month.to_i, day.to_i,
79
- hour.to_i, minute.to_i, second.to_i,
80
- offset_from_zone(zone)
81
- )
82
- end
83
-
84
- def patron_valid?
85
- parse_boolean 'BL'
86
- end
87
-
88
- def authenticated?
89
- parse_boolean 'CQ'
90
- end
91
-
92
- def email
93
- parse_text 'BE'
94
- end
95
-
96
- def location
97
- parse_text 'AQ'
98
- end
99
-
100
- def screen_message
101
- parse_text 'AF'
102
- end
103
-
104
- def inspect
105
- format(
106
- '#<%<class_name>s:0x%<object_id>p @patron_valid="%<patron_valid>s"' \
107
- ' @email="%<email>s" @authenticated="%<authenticated>s">',
108
- class_name: self.class.name,
109
- object_id: object_id,
110
- patron_valid: patron_valid?,
111
- email: email,
112
- authenticated: authenticated?
113
- )
114
- end
115
-
116
- private
117
-
118
- def parse_boolean(message_id)
119
- raw_response[/\|#{message_id}([YN])\|/, 1] == 'Y'
120
- end
121
-
122
- def parse_text(message_id)
123
- raw_response[/\|#{message_id}(.*?)\|/, 1]
124
- end
125
-
126
- def parse_patron_status(position)
127
- parse_fixed_response(position) == 'Y'
128
- end
129
-
130
- def parse_fixed_response(position, count = 1)
131
- raw_response[/\A64.{#{position}}(.{#{count}})/, 1]
132
- end
133
-
134
- def offset_from_zone(zone)
135
- zone.strip!
136
- lookup = TIME_ZONE_LOOKUP_TABLE.find { |_, v| v.include? zone }
137
- lookup ? lookup.first : '+00:00'
138
- end
139
-
140
- TIME_ZONE_LOOKUP_TABLE = {
141
- '-12:00' => %w[Y],
142
- '-11:00' => %w[X BST],
143
- '-10:00' => %w[W HST BDT],
144
- '-09:00' => %w[V YST HDT],
145
- '-08:00' => %w[U PST YDT],
146
- '-07:00' => %w[T MST PDT],
147
- '-06:00' => %w[S CST MDT],
148
- '-05:00' => %w[R EST CDT],
149
- '-04:00' => %w[Q AST EDT],
150
- '-03:00' => %w[P ADT],
151
- '-02:00' => %w[O],
152
- '-01:00' => %w[N],
153
- '+00:00' => %w[Z GMT WET],
154
- '+01:00' => %w[A CET BST],
155
- '+02:00' => %w[B EET],
156
- '+03:00' => %w[C],
157
- '+04:00' => %w[D],
158
- '+05:00' => %w[E],
159
- '+06:00' => %w[F],
160
- '+07:00' => %w[G],
161
- '+08:00' => %w[H SST WST],
162
- '+09:00' => %w[I JST],
163
- '+10:00' => %w[K JDT],
164
- '+11:00' => %w[L],
165
- '+12:00' => %w[M NZST],
166
- '+13:00' => %w[NZDT]
167
- }.freeze
168
-
169
- LANGUAGE_LOOKUP_TABLE = {
170
- '000' => 'Unknown',
171
- '001' => 'English',
172
- '002' => 'French',
173
- '003' => 'German',
174
- '004' => 'Italian',
175
- '005' => 'Dutch',
176
- '006' => 'Swedish',
177
- '007' => 'Finnish',
178
- '008' => 'Spanish',
179
- '009' => 'Danish',
180
- '010' => 'Portuguese',
181
- '011' => 'Canadian-French',
182
- '012' => 'Norwegian',
183
- '013' => 'Hebrew',
184
- '014' => 'Japanese',
185
- '015' => 'Russian',
186
- '016' => 'Arabic',
187
- '017' => 'Polish',
188
- '018' => 'Greek',
189
- '019' => 'Chinese',
190
- '020' => 'Korean',
191
- '021' => 'North American Spanish',
192
- '022' => 'Tamil',
193
- '023' => 'Malay',
194
- '024' => 'United Kingdom',
195
- '025' => 'Icelandic',
196
- '026' => 'Belgian',
197
- '027' => 'Taiwanese'
198
- }.freeze
199
- end
200
- end
data/sip2.gemspec DELETED
@@ -1,27 +0,0 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
-
4
- require 'sip2/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'sip2'
8
- spec.version = Sip2::VERSION
9
- spec.authors = ['abrom']
10
- spec.email = ['a.bromwich@gmail.com']
11
-
12
- spec.summary = '3M™ Standard Interchange Protocol v2 client implementation in Ruby'
13
- spec.description = '3M™ Standard Interchange Protocol v2 client implementation in Ruby'
14
- spec.homepage = 'https://github.com/Studiosity/sip2-ruby'
15
- spec.license = 'MIT'
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
18
- spec.require_paths = ['lib']
19
-
20
- spec.required_ruby_version = '>= 2.2.0'
21
-
22
- spec.add_development_dependency 'bundler', '>= 1.11'
23
- spec.add_development_dependency 'rake', '>= 10.0'
24
- spec.add_development_dependency 'rspec', '~> 3.0'
25
- spec.add_development_dependency 'rubocop', '~> 0'
26
- spec.add_development_dependency 'timecop', '~> 0'
27
- end