sip2-ruby 0.1.0 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35f09dc0ff1cc1cc6d033faf06eb5ec6108d37c4f9cd89d3e63ecf66614292ab
4
- data.tar.gz: 6e21ab95f53d364cc215eeb66db6f540d0315cc203a355476d172d13bb7aaccd
3
+ metadata.gz: 96d721046557a0efc45a7c605b25f55ff1b5e9269fb4efe44b79891e2ae6cdb2
4
+ data.tar.gz: d42791627df1b51319116ab60ccbb4e177a455644979b4973b8a0c9d3b00c389
5
5
  SHA512:
6
- metadata.gz: f695891e29b8ada0c7ec5fa68b606931fa5f0f4b866bd0e4cf02c1914dbe5a29013313384af73f76eae04f9b18d4078df03ddfbb9e558f48124a3c22b9edcc5b
7
- data.tar.gz: 7ca77c9993bef861c547ef2405be6da9d0383cd3065be6464b582acfc50b9a13709e6227e288474e696c6481e3adddaf312b7bc814a15ce1328d6624fa76efa4
6
+ metadata.gz: e25c2e31d3fed713558137f339aa9d224e73d5fdb0a241ce4add781ee4c710b8ccf0664beb57d1eff2dc244509d1e119011957086c04d314ffdb83e11ef4ca99
7
+ data.tar.gz: f96394c636f0c8215d8a0c79f60c27d9278d5d499f2287b650f19ddbf30cb53d0847497ceafc2b5bdeb6e5b9be0ea9f9fee8e672bca1c92ac5e15960532ee386
data/environment.rb ADDED
@@ -0,0 +1,2 @@
1
+ lib = File.join(__dir__, "lib")
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
data/lib/sip2/messages.rb CHANGED
@@ -619,7 +619,10 @@ module Sip2
619
619
  required_delimited_fields: [],
620
620
  optional_delimited_fields: [],
621
621
  },
622
- ]
622
+ ].map { |msg|
623
+ msg[:symbol] = msg[:name].downcase.gsub(" ", "_").to_sym
624
+ msg
625
+ }
623
626
 
624
627
  MESSAGES_BY_CODE = MESSAGES
625
628
  .group_by { |m| m[:code] }
@@ -9,7 +9,7 @@ module Sip2
9
9
  rule(nil: simple(:_)) { nil }
10
10
  rule(empty_hash: simple(:_)) { {} }
11
11
 
12
- rule(int: simple(:x)) { Integer(x) }
12
+ rule(int: simple(:x)) { Integer(x, 10) }
13
13
 
14
14
  rule(int: sequence(:x)) { x.empty? ? 0 : x }
15
15
 
@@ -70,7 +70,10 @@ module Sip2
70
70
  hsh.fetch(k) { hsh[k] = [] } << v
71
71
  }
72
72
  else
73
- hsh.merge!(el)
73
+ el.each do |k,v|
74
+ warn "Overwriting duplicate field: #{k}" if hsh.key?(k)
75
+ hsh[k] = v
76
+ end
74
77
  end
75
78
  }
76
79
  }
data/lib/sip2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sip2
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../environment"
4
+
5
+ require 'json'
6
+ require "sip2/messages"
7
+
8
+ puts JSON.dump(Sip2::MESSAGES)
data/sip2-ruby.gemspec CHANGED
@@ -13,22 +13,24 @@ Gem::Specification.new do |spec|
13
13
  EOS
14
14
  spec.homepage = "https://github.com/ub-library/sip2-ruby"
15
15
  spec.license = "MIT"
16
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
17
17
 
18
18
  spec.metadata["homepage_uri"] = spec.homepage
19
19
  spec.metadata["source_code_uri"] = spec.homepage
20
-
20
+ spec.metadata["changelog_uri"] = spec.homepage + "/blob/main/CHANGES.md"
21
21
  spec.files = Dir.glob("{lib,test}/**/*") + %w[
22
22
  LICENSE.txt
23
- Rakefile
24
23
  README.md
24
+ Rakefile
25
+ environment.rb
26
+ script/sip2-messages-info
25
27
  sip2-ruby.gemspec
26
28
  ]
27
29
  spec.bindir = "bin"
28
30
  spec.executables = %w[sip2-to-json json-to-sip2]
29
31
  spec.require_paths = %w[lib]
30
32
 
31
- spec.add_runtime_dependency "dry-struct", "~> 1.4"
33
+ spec.add_runtime_dependency "dry-struct", ">= 1.4", "< 1.9"
32
34
  spec.add_runtime_dependency "parslet", "~> 2.0"
33
35
  spec.add_runtime_dependency "yajl-ruby", "~> 1.4"
34
36
 
data/test/sip2_spec.rb CHANGED
@@ -140,6 +140,56 @@ describe Sip2 do
140
140
  end
141
141
 
142
142
  end
143
- end
143
+
144
+ describe "Messages with duplicate fields" do
145
+ let(:base_message) { sip2_fixture("18") }
146
+
147
+ it "combines repeatable fields into arrays" do
148
+ # Insert print_line fields after the title field
149
+ msg = base_message.sub(
150
+ "|AJSome example title by Some Author|",
151
+ "|AJSome example title by Some Author|AGFirst print line|AGSecond print line|"
152
+ )
153
+
154
+ result = Sip2.parse(msg).first
155
+ assert_equal ["First print line", "Second print line"], result[:print_line]
156
+ end
157
+
158
+ it "keeps last value for duplicate non-repeatable fields" do
159
+ # Insert duplicate location field after the first one
160
+ msg = base_message.sub(
161
+ "|APSomeLocation|",
162
+ "|APFirstLocation|APSecondLocation|"
163
+ )
164
+
165
+ result = Sip2.parse(msg).first
166
+ assert_equal "SecondLocation", result[:current_location]
167
+ end
168
+
169
+ it "warns about duplicate non-repeatable fields" do
170
+ msg = base_message.sub(
171
+ "|APSomeLocation|",
172
+ "|APFirstLocation|APSecondLocation|"
173
+ )
174
+
175
+ assert_output(nil, /Overwriting duplicate field: current_location/) do
176
+ Sip2.parse(msg)
177
+ end
178
+ end
179
+
180
+ it "handles multiple types of repeatable fields in any order" do
181
+ msg = base_message.sub(
182
+ "|AJSome example title by Some Author|",
183
+ "|AJSome example title by Some Author|" \
184
+ "AGFirst print line|AFFirst screen msg|" \
185
+ "AFSecond screen msg|AGSecond print line|" # Interspersed order
186
+ )
187
+
188
+ result = Sip2.parse(msg).first
189
+ assert_equal ["First print line", "Second print line"], result[:print_line]
190
+ assert_equal ["First screen msg", "Second screen msg"], result[:screen_message]
191
+ end
192
+ end
193
+ end
144
194
 
145
195
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sip2-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Sandbecker
@@ -14,16 +14,22 @@ dependencies:
14
14
  name: dry-struct
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.9'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.9'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: parslet
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +130,7 @@ files:
124
130
  - Rakefile
125
131
  - bin/json-to-sip2
126
132
  - bin/sip2-to-json
133
+ - environment.rb
127
134
  - lib/sip2.rb
128
135
  - lib/sip2/checksum_encoder.rb
129
136
  - lib/sip2/field_parser_rules.rb
@@ -138,6 +145,7 @@ files:
138
145
  - lib/sip2/transformer.rb
139
146
  - lib/sip2/types.rb
140
147
  - lib/sip2/version.rb
148
+ - script/sip2-messages-info
141
149
  - sip2-ruby.gemspec
142
150
  - test/fixture_helper.rb
143
151
  - test/fixtures/09.sip2
@@ -168,6 +176,7 @@ licenses:
168
176
  metadata:
169
177
  homepage_uri: https://github.com/ub-library/sip2-ruby
170
178
  source_code_uri: https://github.com/ub-library/sip2-ruby
179
+ changelog_uri: https://github.com/ub-library/sip2-ruby/blob/main/CHANGES.md
171
180
  post_install_message:
172
181
  rdoc_options: []
173
182
  require_paths:
@@ -176,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
185
  requirements:
177
186
  - - ">="
178
187
  - !ruby/object:Gem::Version
179
- version: 2.3.0
188
+ version: 2.6.0
180
189
  required_rubygems_version: !ruby/object:Gem::Requirement
181
190
  requirements:
182
191
  - - ">="