bismas 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10c30809ae5cda2ad399baae90e9879c5cb51e2c
4
- data.tar.gz: 44f15ed29547cc3ccde3b254b03a63c52f15a66b
3
+ metadata.gz: b7b1bf402b54716f33ab4776f2a152f9245d178a
4
+ data.tar.gz: 0bc6073adeaa2182c8c181a8c440ac01501c9254
5
5
  SHA512:
6
- metadata.gz: 90b376637badd518248f399b064566beca1b08a78a1df26f7cac793ba4e2cbad6cbb0af4c4a48e537435d7144c03649061aad09b275b3cf29d38331ed67f486e
7
- data.tar.gz: 0d39167f777572ebcd6ba9e614831e94755bb4b8fc0d8ac2abff6e0d27774c65327741079a059a5798d618d616675d5182001b58cc6a304604259d75c25ad407
6
+ metadata.gz: 39d7e051dd26e865533325f22a7dd19ef4d33998a7b35a3ee31a38c4099fd5495ac0bb9657cce20b4f430941a7346cb088ee74befb85742a7c4f92971c3fefea
7
+ data.tar.gz: 8e0b39dbc62b974df0f692bc271b5b902e3603acf34c42befab1029686a96dbac192537d7b80b18f560ff138660943dd4edfc567c56e436eede8f25b50ef561a
data/ChangeLog CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  = Revision history for bismas
4
4
 
5
+ == 0.2.0 [2015-12-03]
6
+
7
+ * Added <tt>.CAT</tt> parser.
8
+ * Fixed Bismas.amend_encoding to accept encoding object.
9
+
5
10
  == 0.1.0 [2015-11-20]
6
11
 
7
12
  * First release.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to bismas version 0.1.0.
5
+ This documentation refers to bismas version 0.2.0.
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -131,8 +131,10 @@ module Bismas
131
131
  end
132
132
 
133
133
  def amend_encoding(options, default_encoding = DEFAULT_ENCODING)
134
- (options[:encoding] ||= default_encoding).tap { |encoding|
135
- encoding.prepend(default_encoding) if encoding.start_with?(':') }
134
+ encoding = options.fetch(:encoding, default_encoding).to_s
135
+
136
+ options[:encoding] = encoding.start_with?(':') ?
137
+ default_encoding.to_s + encoding : encoding
136
138
  end
137
139
 
138
140
  end
@@ -143,4 +145,5 @@ require_relative 'bismas/base'
143
145
  require_relative 'bismas/reader'
144
146
  require_relative 'bismas/writer'
145
147
  require_relative 'bismas/mapping'
148
+ require_relative 'bismas/categories'
146
149
  require_relative 'bismas/version'
@@ -0,0 +1,75 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # bismas -- A Ruby client for BISMAS databases #
5
+ # #
6
+ # Copyright (C) 2015 Jens Wille #
7
+ # #
8
+ # Authors: #
9
+ # Jens Wille <jens.wille@gmail.com> #
10
+ # #
11
+ # bismas is free software; you can redistribute it and/or modify it #
12
+ # under the terms of the GNU Affero General Public License as published by #
13
+ # the Free Software Foundation; either version 3 of the License, or (at your #
14
+ # option) any later version. #
15
+ # #
16
+ # bismas is distributed in the hope that it will be useful, but #
17
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
18
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
19
+ # License for more details. #
20
+ # #
21
+ # You should have received a copy of the GNU Affero General Public License #
22
+ # along with bismas. If not, see <http://www.gnu.org/licenses/>. #
23
+ # #
24
+ ###############################################################################
25
+ #++
26
+
27
+ module Bismas
28
+
29
+ class Categories
30
+
31
+ FIELD_RE = %r{\Afeld\s+=\s+(\d+)}i
32
+
33
+ CATEGORY_RE = lambda { |category_length|
34
+ %r{\A(.{#{category_length}})"(.+?)"} }
35
+
36
+ def self.parse_file(file, options = {})
37
+ Bismas.amend_encoding(options)
38
+
39
+ categories, category_re = new, nil
40
+
41
+ File.foreach(file, options) { |line|
42
+ case line
43
+ when FIELD_RE
44
+ category_re = CATEGORY_RE[$1.to_i]
45
+ when category_re
46
+ categories[$1.strip] = $2.strip
47
+ end
48
+ }
49
+
50
+ categories
51
+ end
52
+
53
+ def initialize
54
+ @categories = {}
55
+ end
56
+
57
+ def categories
58
+ @categories.keys
59
+ end
60
+
61
+ def [](key)
62
+ @categories[key]
63
+ end
64
+
65
+ def []=(key, value)
66
+ @categories[key] = value
67
+ end
68
+
69
+ def to_h
70
+ @categories
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -3,7 +3,7 @@ module Bismas
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 1
6
+ MINOR = 2
7
7
  TINY = 0
8
8
 
9
9
  class << self
@@ -1,5 +1,13 @@
1
1
  describe Bismas::Reader do
2
2
 
3
+ example do
4
+ expect(described_class.parse_file(data('test.dat')).size).to eq(14)
5
+ end
6
+
7
+ example do
8
+ expect(described_class.parse_file(data('test.dat'), encoding: Encoding::CP850).size).to eq(14)
9
+ end
10
+
3
11
  example do
4
12
  expect(described_class.parse_file(data('test.dat'), strict: true)).to eq({
5
13
  1 => { "005" => ["Bock, F."], "020" => ["Zur Geschichte des Schlagwortkatalogs in Praxis und Theorie"], "030" => ["Zentralblatt f\x81r Bibliothekswesen. 40(1923), S.494-502."], "055" => ["1923"], "060" => ["Geschichte des Schlagwortkataloges"], "059" => ["d"], "053" => ["a"], "120" => ["D"] },
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bismas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cyclops
@@ -103,6 +103,7 @@ files:
103
103
  - bin/bismas
104
104
  - lib/bismas.rb
105
105
  - lib/bismas/base.rb
106
+ - lib/bismas/categories.rb
106
107
  - lib/bismas/cli.rb
107
108
  - lib/bismas/mapping.rb
108
109
  - lib/bismas/parser.rb
@@ -119,13 +120,14 @@ licenses:
119
120
  metadata: {}
120
121
  post_install_message: |2+
121
122
 
122
- bismas-0.1.0 [2015-11-20]:
123
+ bismas-0.2.0 [2015-12-03]:
123
124
 
124
- * First release.
125
+ * Added <tt>.CAT</tt> parser.
126
+ * Fixed Bismas.amend_encoding to accept encoding object.
125
127
 
126
128
  rdoc_options:
127
129
  - "--title"
128
- - bismas Application documentation (v0.1.0)
130
+ - bismas Application documentation (v0.2.0)
129
131
  - "--charset"
130
132
  - UTF-8
131
133
  - "--line-numbers"