marc 1.0.4 → 1.2.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.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +30 -0
- data/.github/workflows/ruby.yml +24 -0
- data/.gitignore +17 -0
- data/.standard.yml +1 -0
- data/{Changes → CHANGELOG.md} +106 -29
- data/Gemfile +15 -0
- data/README.md +240 -47
- data/Rakefile +14 -14
- data/bin/marc +14 -0
- data/bin/marc2xml +17 -0
- data/examples/xml2marc.rb +10 -0
- data/lib/marc/constants.rb +3 -3
- data/lib/marc/controlfield.rb +35 -23
- data/lib/marc/datafield.rb +70 -63
- data/lib/marc/dublincore.rb +59 -41
- data/lib/marc/exception.rb +9 -1
- data/lib/marc/jsonl_reader.rb +33 -0
- data/lib/marc/jsonl_writer.rb +44 -0
- data/lib/marc/marc8/map_to_unicode.rb +16417 -16420
- data/lib/marc/marc8/to_unicode.rb +80 -86
- data/lib/marc/reader.rb +119 -121
- data/lib/marc/record.rb +72 -62
- data/lib/marc/subfield.rb +12 -10
- data/lib/marc/unsafe_xmlwriter.rb +93 -0
- data/lib/marc/version.rb +1 -1
- data/lib/marc/writer.rb +27 -30
- data/lib/marc/xml_parsers.rb +222 -197
- data/lib/marc/xmlreader.rb +131 -114
- data/lib/marc/xmlwriter.rb +93 -81
- data/lib/marc.rb +20 -18
- data/marc.gemspec +23 -0
- data/test/marc8/tc_marc8_mapping.rb +3 -3
- data/test/marc8/tc_to_unicode.rb +28 -32
- data/test/messed_up_leader.xml +9 -0
- data/test/tc_controlfield.rb +37 -34
- data/test/tc_datafield.rb +65 -60
- data/test/tc_dublincore.rb +9 -11
- data/test/tc_hash.rb +10 -13
- data/test/tc_jsonl.rb +19 -0
- data/test/tc_marchash.rb +17 -21
- data/test/tc_parsers.rb +108 -144
- data/test/tc_reader.rb +35 -36
- data/test/tc_reader_char_encodings.rb +149 -169
- data/test/tc_record.rb +143 -148
- data/test/tc_subfield.rb +14 -13
- data/test/tc_unsafe_xml.rb +95 -0
- data/test/tc_writer.rb +101 -108
- data/test/tc_xml.rb +99 -87
- data/test/tc_xml_error_handling.rb +7 -8
- data/test/ts_marc.rb +8 -8
- metadata +94 -9
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "marc/writer"
|
5
|
+
|
6
|
+
module MARC
|
7
|
+
class JSONLWriter < MARC::Writer
|
8
|
+
# @param [String, IO] file A filename, or open File/IO type object, from which to read
|
9
|
+
def initialize(file, &blk)
|
10
|
+
if file.instance_of?(String)
|
11
|
+
@fh = File.new(file, "w:utf-8")
|
12
|
+
elsif file.respond_to?(:write)
|
13
|
+
@fh = file
|
14
|
+
else
|
15
|
+
raise ArgumentError, "must pass in file name or handle"
|
16
|
+
end
|
17
|
+
|
18
|
+
if blk
|
19
|
+
blk.call(self)
|
20
|
+
close
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Write encoded record to the handle
|
25
|
+
# @param [MARC::Record] record
|
26
|
+
# @return [MARC::JSONLWriter] self
|
27
|
+
def write(record)
|
28
|
+
@fh.puts(encode(record))
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
# Encode the record as a marc-in-json string
|
33
|
+
# @param [MARC::Record] record
|
34
|
+
# @return [String] MARC-in-JSON representation of the record
|
35
|
+
def self.encode(record)
|
36
|
+
JSON.fast_generate(record.to_hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @see MARC::JSONLWriter.encode
|
40
|
+
def encode(rec)
|
41
|
+
self.class.encode(rec)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|