berkeley_library-tind 0.5.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +15 -3
  3. data/.gitignore +3 -0
  4. data/.idea/inspectionProfiles/Project_Default.xml +10 -0
  5. data/.idea/tind.iml +10 -9
  6. data/.rubocop.yml +1 -1
  7. data/CHANGES.md +15 -1
  8. data/README.md +165 -2
  9. data/berkeley_library-tind.gemspec +2 -2
  10. data/bin/alma-multiple-tind +50 -0
  11. data/bin/alma-single-tind +48 -0
  12. data/bin/save_tind_records +80 -0
  13. data/bin/tind-marc +73 -0
  14. data/lib/berkeley_library/tind/export/ods_exporter.rb +4 -6
  15. data/lib/berkeley_library/tind/mapping/additional_datafield_process.rb +128 -0
  16. data/lib/berkeley_library/tind/mapping/alma.rb +42 -0
  17. data/lib/berkeley_library/tind/mapping/alma_base.rb +108 -0
  18. data/lib/berkeley_library/tind/mapping/alma_multiple_tind.rb +31 -0
  19. data/lib/berkeley_library/tind/mapping/alma_single_tind.rb +28 -0
  20. data/lib/berkeley_library/tind/mapping/config.rb +44 -0
  21. data/lib/berkeley_library/tind/mapping/csv_mapper.rb +35 -0
  22. data/lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb +41 -0
  23. data/lib/berkeley_library/tind/mapping/data/one_to_multiple_mapping.csv +4 -0
  24. data/lib/berkeley_library/tind/mapping/data/one_to_one_mapping.csv +39 -0
  25. data/lib/berkeley_library/tind/mapping/external_tind_field.rb +103 -0
  26. data/lib/berkeley_library/tind/mapping/field_catalog.rb +137 -0
  27. data/lib/berkeley_library/tind/mapping/field_catalog_util.rb +105 -0
  28. data/lib/berkeley_library/tind/mapping/match_tind_field.rb +77 -0
  29. data/lib/berkeley_library/tind/mapping/misc.rb +69 -0
  30. data/lib/berkeley_library/tind/mapping/multiple_rule.rb +36 -0
  31. data/lib/berkeley_library/tind/mapping/single_rule.rb +149 -0
  32. data/lib/berkeley_library/tind/mapping/tind_control_subfield.rb +59 -0
  33. data/lib/berkeley_library/tind/mapping/tind_field.rb +49 -0
  34. data/lib/berkeley_library/tind/mapping/tind_field_from_leader.rb +27 -0
  35. data/lib/berkeley_library/tind/mapping/tind_field_from_multiple_map.rb +59 -0
  36. data/lib/berkeley_library/tind/mapping/tind_field_from_single_map.rb +182 -0
  37. data/lib/berkeley_library/tind/mapping/tind_field_util.rb +112 -0
  38. data/lib/berkeley_library/tind/mapping/tind_marc.rb +134 -0
  39. data/lib/berkeley_library/tind/mapping/tind_record_util.rb +135 -0
  40. data/lib/berkeley_library/tind/mapping/tind_subfield_util.rb +154 -0
  41. data/lib/berkeley_library/tind/mapping/util.rb +136 -0
  42. data/lib/berkeley_library/tind/mapping.rb +1 -0
  43. data/lib/berkeley_library/tind/module_info.rb +1 -1
  44. data/spec/berkeley_library/tind/mapping/additional_datafield_process_spec.rb +35 -0
  45. data/spec/berkeley_library/tind/mapping/alma_base_spec.rb +115 -0
  46. data/spec/berkeley_library/tind/mapping/alma_multiple_tind_spec.rb +20 -0
  47. data/spec/berkeley_library/tind/mapping/alma_single_tind_spec.rb +87 -0
  48. data/spec/berkeley_library/tind/mapping/alma_spec.rb +28 -0
  49. data/spec/berkeley_library/tind/mapping/config_spec.rb +19 -0
  50. data/spec/berkeley_library/tind/mapping/csv_mapper_spec.rb +27 -0
  51. data/spec/berkeley_library/tind/mapping/csv_multiple_mapper_spec.rb +27 -0
  52. data/spec/berkeley_library/tind/mapping/external_tind_field_spec.rb +45 -0
  53. data/spec/berkeley_library/tind/mapping/field_catalog_spec.rb +78 -0
  54. data/spec/berkeley_library/tind/mapping/field_catalog_util_spec.rb +105 -0
  55. data/spec/berkeley_library/tind/mapping/match_tind_field_spec.rb +24 -0
  56. data/spec/berkeley_library/tind/mapping/misc_spec.rb +51 -0
  57. data/spec/berkeley_library/tind/mapping/multiple_rule_spec.rb +44 -0
  58. data/spec/berkeley_library/tind/mapping/single_rule_spec.rb +52 -0
  59. data/spec/berkeley_library/tind/mapping/tind_control_subfield_spec.rb +96 -0
  60. data/spec/berkeley_library/tind/mapping/tind_field_from_leader_spec.rb +21 -0
  61. data/spec/berkeley_library/tind/mapping/tind_field_from_multiple_map_spec.rb +31 -0
  62. data/spec/berkeley_library/tind/mapping/tind_field_from_single_map_spec.rb +167 -0
  63. data/spec/berkeley_library/tind/mapping/tind_field_spec.rb +60 -0
  64. data/spec/berkeley_library/tind/mapping/tind_field_util_spec.rb +68 -0
  65. data/spec/berkeley_library/tind/mapping/tind_marc_spec.rb +88 -0
  66. data/spec/berkeley_library/tind/mapping/tind_record_util_spec.rb +30 -0
  67. data/spec/berkeley_library/tind/mapping/tind_subfield_util_spec.rb +48 -0
  68. data/spec/berkeley_library/tind/mapping/util_spec.rb +56 -0
  69. data/spec/berkeley_library/tind/marc/xml_writer_spec.rb +24 -0
  70. data/spec/data/api/pre_assigned_response.json +15 -0
  71. data/spec/data/api/result_file.csv +3 -0
  72. data/spec/data/api/upload_file.json +1 -0
  73. data/spec/data/api/upload_response.json +13 -0
  74. data/spec/data/mapping/991032333019706532-sru.xml +216 -0
  75. data/spec/data/mapping/one_to_multiple_mapping.csv +4 -0
  76. data/spec/data/mapping/one_to_one_mapping.csv +39 -0
  77. data/spec/data/mapping/record.xml +266 -0
  78. data/spec/data/mapping/record_not_qualified.xml +36 -0
  79. metadata +89 -54
  80. data/lib/berkeley_library/util/files.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24232cda73f63d90367c05453c325f468d6103d667e820671f19c251cabd3814
4
- data.tar.gz: 98d09880d886d8f351f0a038b8513aefe5dfe5c3a72108f634d79f7ad2485506
3
+ metadata.gz: 7e02344bc1a5d5c119c860bd357dfac55753bc809149cef7a068941f0566682c
4
+ data.tar.gz: aaba20e6650860ef0d89619522264746f1e689800e20abde0247ca0a3c55bad2
5
5
  SHA512:
6
- metadata.gz: 15c2560d8bee4b55fbb66a51f101afd731ef02bf542c7e4433ea0b095efa492a9b7429a7bb8929226079bb24a40a9f5e27432c6c855812a0a29d913d6877958e
7
- data.tar.gz: 6133181a93ef7a1204e6c73ea56a5fdee80f40817bfbe87c3c03ed063ec070e8c6f50dff732bbd987e30b929c14ba6e0b056a0b259f8327273f24e7048a069dc
6
+ metadata.gz: c83767367a893dd418c47bc1a74e5d2bf362bceeb009af7427a5e1f240dd4cb5ab57b8c032295e6e253dd5f71f5b512fd2bf112b1734a80d22d62a06b92d6c28
7
+ data.tar.gz: 224863c5c06224dbc4c2caae4e73c7f1752ee1f5303a758af1428667a938bb561a2d97e0a31306627cd37325e4518d4f674e22d270f2bcd40e631b90265eb62f
@@ -10,9 +10,21 @@ jobs:
10
10
  runs-on: ${{ matrix.os }}
11
11
 
12
12
  steps:
13
- - uses: actions/checkout@v2
14
- - uses: ruby/setup-ruby@v1
13
+ - name: Check out repository
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
15
18
  with:
16
19
  ruby-version: ${{ matrix.ruby }}
17
20
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
18
- - run: bundle exec rake
21
+
22
+ - name: Run checks
23
+ run: bundle exec rake
24
+
25
+ - name: Upload artifacts
26
+ if: ${{ always() }}
27
+ uses: actions/upload-artifact@v3
28
+ with:
29
+ name: artifacts
30
+ path: artifacts/**
data/.gitignore CHANGED
@@ -7,6 +7,9 @@
7
7
  # Additional IDEA/RubyMine ignores
8
8
  .idea/.rakeTasks
9
9
 
10
+ # Visual Studio Code ignores
11
+ .vscode
12
+
10
13
  # Don't commit Gemfile.lock for libraries
11
14
  Gemfile.lock
12
15
 
@@ -10,6 +10,14 @@
10
10
  <inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
11
11
  <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
12
12
  <inspection_tool class="RubyCaseWithoutElseBlockInspection" enabled="false" level="WARNING" enabled_by_default="false" />
13
+ <inspection_tool class="RubyClassMethodNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
14
+ <inspection_tool class="RubyClassModuleNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
15
+ <inspection_tool class="RubyClassVariableNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
16
+ <inspection_tool class="RubyConstantNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
17
+ <inspection_tool class="RubyGlobalVariableNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
18
+ <inspection_tool class="RubyInstanceMethodNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
19
+ <inspection_tool class="RubyInstanceVariableNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
20
+ <inspection_tool class="RubyLocalVariableNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
13
21
  <inspection_tool class="RubyMismatchedArgumentType" enabled="true" level="WARNING" enabled_by_default="true">
14
22
  <option name="myCheckNilability" value="false" />
15
23
  </inspection_tool>
@@ -28,6 +36,8 @@
28
36
  <inspection_tool class="RubyMismatchedVariableType" enabled="true" level="WARNING" enabled_by_default="true">
29
37
  <option name="myCheckNilability" value="false" />
30
38
  </inspection_tool>
39
+ <inspection_tool class="RubyNilAnalysis" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
40
+ <inspection_tool class="RubyParameterNamingConvention" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
31
41
  <inspection_tool class="RubyStringKeysInHashInspection" enabled="true" level="INFORMATION" enabled_by_default="true" />
32
42
  <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
33
43
  <option name="processCode" value="true" />
data/.idea/tind.iml CHANGED
@@ -9,15 +9,16 @@
9
9
  </content>
10
10
  <orderEntry type="jdk" jdkName="RVM: ruby-2.7.5" jdkType="RUBY_SDK" />
11
11
  <orderEntry type="sourceFolder" forTests="false" />
12
- <orderEntry type="library" scope="PROVIDED" name="actionpack (v7.0.2.3, RVM: ruby-2.7.5) [gem]" level="application" />
13
- <orderEntry type="library" scope="PROVIDED" name="actionview (v7.0.2.3, RVM: ruby-2.7.5) [gem]" level="application" />
14
- <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.0.2.3, RVM: ruby-2.7.5) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="actionpack (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="actionview (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
15
15
  <orderEntry type="library" scope="PROVIDED" name="addressable (v2.8.0, RVM: ruby-2.7.5) [gem]" level="application" />
16
16
  <orderEntry type="library" scope="PROVIDED" name="amazing_print (v1.4.0, RVM: ruby-2.7.5) [gem]" level="application" />
17
17
  <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.5) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="berkeley_library-alma (v0.0.4, RVM: ruby-2.7.5) [gem]" level="application" />
18
19
  <orderEntry type="library" scope="PROVIDED" name="berkeley_library-logging (v0.2.6, RVM: ruby-2.7.5) [gem]" level="application" />
19
20
  <orderEntry type="library" scope="PROVIDED" name="berkeley_library-marc (v0.3.1, RVM: ruby-2.7.5) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="berkeley_library-util (v0.1.1, RVM: ruby-2.7.5) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="berkeley_library-util (v0.1.2, RVM: ruby-2.7.5) [gem]" level="application" />
21
22
  <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
22
23
  <orderEntry type="library" scope="PROVIDED" name="bundle-audit (v0.1.0, RVM: ruby-2.7.5) [gem]" level="application" />
23
24
  <orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.31, RVM: ruby-2.7.5) [gem]" level="application" />
@@ -39,15 +40,15 @@
39
40
  <orderEntry type="library" scope="PROVIDED" name="http-cookie (v1.0.4, RVM: ruby-2.7.5) [gem]" level="application" />
40
41
  <orderEntry type="library" scope="PROVIDED" name="i18n (v1.10.0, RVM: ruby-2.7.5) [gem]" level="application" />
41
42
  <orderEntry type="library" scope="PROVIDED" name="ice_nine (v0.11.2, RVM: ruby-2.7.5) [gem]" level="application" />
42
- <orderEntry type="library" scope="PROVIDED" name="lograge (v0.11.2, RVM: ruby-2.7.5) [gem]" level="application" />
43
- <orderEntry type="library" scope="PROVIDED" name="loofah (v2.15.0, RVM: ruby-2.7.5) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="lograge (v0.12.0, RVM: ruby-2.7.5) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="loofah (v2.17.0, RVM: ruby-2.7.5) [gem]" level="application" />
44
45
  <orderEntry type="library" scope="PROVIDED" name="marc (v1.1.1, RVM: ruby-2.7.5) [gem]" level="application" />
45
46
  <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, RVM: ruby-2.7.5) [gem]" level="application" />
46
47
  <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.4.1, RVM: ruby-2.7.5) [gem]" level="application" />
47
48
  <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2022.0105, RVM: ruby-2.7.5) [gem]" level="application" />
48
49
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, RVM: ruby-2.7.5) [gem]" level="application" />
49
50
  <orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, RVM: ruby-2.7.5) [gem]" level="application" />
50
- <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.1, RVM: ruby-2.7.5) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.5, RVM: ruby-2.7.5) [gem]" level="application" />
51
52
  <orderEntry type="library" scope="PROVIDED" name="oj (v3.13.11, RVM: ruby-2.7.5) [gem]" level="application" />
52
53
  <orderEntry type="library" scope="PROVIDED" name="ougai (v1.9.1, RVM: ruby-2.7.5) [gem]" level="application" />
53
54
  <orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, RVM: ruby-2.7.5) [gem]" level="application" />
@@ -59,7 +60,7 @@
59
60
  <orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, RVM: ruby-2.7.5) [gem]" level="application" />
60
61
  <orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, RVM: ruby-2.7.5) [gem]" level="application" />
61
62
  <orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.2, RVM: ruby-2.7.5) [gem]" level="application" />
62
- <orderEntry type="library" scope="PROVIDED" name="railties (v7.0.2.3, RVM: ruby-2.7.5) [gem]" level="application" />
63
+ <orderEntry type="library" scope="PROVIDED" name="railties (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
63
64
  <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-2.7.5) [gem]" level="application" />
64
65
  <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-2.7.5) [gem]" level="application" />
65
66
  <orderEntry type="library" scope="PROVIDED" name="rchardet (v1.8.0, RVM: ruby-2.7.5) [gem]" level="application" />
@@ -110,7 +111,7 @@
110
111
  </RakeTaskImpl>
111
112
  <RakeTaskImpl description="Run all specs in spec directory, with coverage" fullCommand="coverage" id="coverage" />
112
113
  <RakeTaskImpl description="Run tests, check test coverage, check code style, check for vulnerabilities, build gem" fullCommand="default" id="default" />
113
- <RakeTaskImpl description="Build berkeley_library-tind.gemspec as berkeley_library-tind-0.4.3.gem" fullCommand="gem" id="gem" />
114
+ <RakeTaskImpl description="Build berkeley_library-tind.gemspec as berkeley_library-tind-0.6.0.gem" fullCommand="gem" id="gem" />
114
115
  <RakeTaskImpl description="Run RuboCop with auto-correct, and output results to console" fullCommand="ra" id="ra" />
115
116
  <RakeTaskImpl description="Run rubocop with HTML output" fullCommand="rubocop" id="rubocop" />
116
117
  <RakeTaskImpl id="rubocop">
data/.rubocop.yml CHANGED
@@ -331,4 +331,4 @@ Style/SwapValues: # (new in 1.1)
331
331
  Gemspec/DateAssignment: # (new in 1.10)
332
332
  Enabled: true
333
333
  Style/HashConversion: # (new in 1.10)
334
- Enabled: true
334
+ Enabled: true
data/CHANGES.md CHANGED
@@ -1,4 +1,18 @@
1
- # 0.5.1 (2023-03-23)
1
+ # 0.7.0 (2022-10-26)
2
+
3
+ - Preserves subfield order insofar as possible when mapping Alma records to TIND.
4
+ - Adds collection-specific configuration for mapping Alma records to TIND.
5
+ - Adds `BerkeleyLibrary::TIND::Mapping::TindRecordUtil` class for manipulating
6
+ subfields in TIND MARC records.
7
+ - Removes `BerkeleyLibrary::Util::Files` class, which is now part of `berkeley_library-util`.
8
+
9
+ # 0.6.0 (2022-04-06)
10
+
11
+ - Adds `BerkeleyLibrary::TIND::Mapping` module to map MARC records from Alma to TIND.
12
+ - `BerkeleyLibrary::TIND::MARC::XMLWriter` now assumes that any object that response to `:write`
13
+ and `:close` is suffiently `IO`-like to write to.
14
+
15
+ # 0.5.1 (2022-03-23)
2
16
 
3
17
  - Fix an issue where `BerkeleyLibrary::TIND::MARC::XMLWriter` would drop fields with nonstandard tags (e.g. `FFT` fields)
4
18
  and would group and sort fields by tag instead of preserving the original order.
data/README.md CHANGED
@@ -30,7 +30,7 @@ To access the TIND API, you will need to set:
30
30
  it a "key", so that's the term we use here.)
31
31
 
32
32
  These can be set directly, via accessors in the `BerkeleyLibrary::TIND::Config` module;
33
- if they are not set, a value will be read from the environment, and if no
33
+ if they are not set, a value will be read from the environment, and if no
34
34
  value is present in the environment and Rails is loaded, from the Rails
35
35
  application configuration (`Rails.application.config`).
36
36
 
@@ -43,9 +43,18 @@ application configuration (`Rails.application.config`).
43
43
  object, but will always be returned as a `URI` object, and an invalid
44
44
  string setting will raise `URI::InvalidURIError`.
45
45
 
46
+ ### Alma configuration
47
+
48
+ When mapping Alma records to TIND (see below), this gem uses
49
+ [`berkeley_library-alma`](https://github.com/BerkeleyLibrary/alma) to load
50
+ Alma records. The scripts in the `bin` directory use the default Alma
51
+ configuration; see the `berkeley_library-alma`
52
+ [README](https://github.com/BerkeleyLibrary/alma#configuration) for
53
+ details.
54
+
46
55
  ## Command-line tool: `tind-export`
47
56
 
48
- The `tind-export` command allows you to list TIND collections, or to
57
+ The `tind-export` command allows you to list TIND collections, or to
49
58
  export a TIND collection from the command line. (If the gem is installed,
50
59
  `tind-export` should be in your `$PATH`. If you've cloned the gem source,
51
60
  you can invoke it with `bin/tind-export` from the project root directory.)
@@ -85,3 +94,157 @@ For the full list of options, type `tind-export --help`. Note that you can set
85
94
  the TIND base URL and API key either via the environment, as above, or as options
86
95
  passed to the `tind-export` command. If both an explicit option and an environment
87
96
  variable are set for either, the explicit option takes precedence.
97
+
98
+ ## Mapping MARC records from Alma to TIND
99
+
100
+ ### Transforming Class:
101
+
102
+ 1. BerkeleyLibrary::TIND::Mapping::AlmaSingleTIND (Transforming one Alma record => One TIND record)
103
+ 2. BerkeleyLibrary::TIND::Mapping::AlmaMultipleTIND (Transforming one Alma record => Multiple TIND records)
104
+
105
+ ### Source of TIND fields
106
+
107
+ 1. Mapped from an Alma record (automatically)
108
+
109
+ 2. Derived from collection information, mms_id, and date (automatically)
110
+
111
+ - 336$a
112
+ - 852$c
113
+ - 980$a
114
+ - 982$a,$b
115
+ - 991$a - (optional)
116
+ - 902$d
117
+ - 901$m
118
+ - 85641$u,$y
119
+
120
+ 3. Added at the time of transforming TIND record (fields of a collection or its record)
121
+
122
+ - FFT
123
+ - 035$a
124
+ - 998$a
125
+ - ...
126
+
127
+ ### Example
128
+
129
+ 1. Setup collection information
130
+
131
+ Include below collection level fields:
132
+ - 336: type of resource
133
+ - 852: collection's repository name
134
+ - 980: collection's 980 value
135
+ - 982: collection's short name and long name
136
+ - 991: collection' restricted name (optional)
137
+
138
+ ``` ruby
139
+
140
+ def setup_collection
141
+ # 1. Define collection level field information
142
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.collection_parameter_hash = {
143
+ '336' => ['Image'],
144
+ '852' => ['East Asian Library'],
145
+ '980' => ['pre_1912'],
146
+ '982' => ['Pre 1912 Chinese Materials - short name', 'Pre 1912 Chinese Materials - long name'],
147
+ '991' => []
148
+ }
149
+
150
+ # 2. A flag to include a pre-defined 035 formated in "(980__$a)mms_id",
151
+ # the default value is 'false'
152
+ # BerkeleyLibrary::TIND::Mapping::AlmaBase.is_035_from_mms_id = true
153
+
154
+ # 3. A flag on getting Alma record using Barcode, the defalut value is 'false'
155
+ # BerkeleyLibrary::TIND::Mapping::AlmaBase.is_barcode = true
156
+
157
+ # 4. Define a list of origin tags from an Alma record.
158
+ # Only those related fields (including 880 fields) will be mapped to a TIND record.
159
+ # The default value is []. '001', '008' will be included by default, no need to be listed here.
160
+ # BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[256]
161
+
162
+ # 5. Define a list of origin tags from an Alma record which will be excluded during mapping.
163
+ # The default value is []
164
+ # 1) When the list includes an 880 tag, all 880 fields will be excluded
165
+ # 2) When the list has no 880 tag, only related 880 fields will be excludded
166
+ # BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = %w[245 700]
167
+
168
+ # 6. Not allow to define both #5 and #6. Returning empty fields when defining both #5 and #6
169
+
170
+ end
171
+ ```
172
+
173
+ 2. Praparing additional fields
174
+
175
+ Adding field using:
176
+ - field methods from module: BerkeleyLibrary::TIND::Mapping::TindField
177
+ - Or the original method from Ruby Marc when field method found in above module
178
+ ::MARC::DataField.new(tag, indicator1, indicator, [code1, value1], [code2, value2] ...)
179
+
180
+ ```ruby
181
+
182
+ def additional_tind_fields_1
183
+ txt = 'v001_0064'
184
+ url = 'https://digitalassets.lib.berkeley.edu/pre1912ChineseMaterials/ucb/ready/991032333019706532/991032333019706532_v001_0064.jpg'
185
+ fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, txt)
186
+
187
+ f = ::MARC::DataField.new('998', ' ', ' ', ['a', 'fake-value'])
188
+ [fft] << f
189
+ end
190
+
191
+ def additional_tind_fields_2
192
+ txt = 'v001_0065'
193
+ url = 'https://digitalassets.lib.berkeley.edu/pre1912ChineseMaterials/ucb/ready/991032333019706532/991032333019706532_v001_0065.jpg'
194
+ fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, txt)
195
+ [fft]
196
+ end
197
+ ```
198
+
199
+ 3. Transforming one Alma record => One TIND record
200
+
201
+ ```ruby
202
+ setup_collection
203
+
204
+ # id can be 1)mms_id; 2)Millennium no ; or 3)Barcode
205
+ id = 'C084093187'
206
+
207
+ alma_tind = BerkeleyLibrary::TIND::Mapping::AlmaSingleTIND.new
208
+ tind_record = alma_tind.record(id, additional_tind_fields_1)
209
+ ```
210
+
211
+
212
+ 4. Or transforming one Alma record => Multiple TIND records
213
+
214
+ ``` ruby
215
+ setup_collection
216
+
217
+ # id can be 1) mms_id; 2) Millennium bib number; or 3) Item barcode
218
+ # id = '991085821143406532'
219
+ id = 'C084093187'
220
+
221
+ alma_tind = BerkeleyLibrary::TIND::Mapping::AlmaMultipleTIND.new(id)
222
+ tind_record_1 = alma_tind.record(additional_tind_fields_1)
223
+ tind_record_2 = alma_tind.record(additional_tind_fields_2)
224
+ ```
225
+
226
+ 5. Updating TIND record with TindRecordUtil : 1) add/update subfields to one-occurrenced field; 2) remove fields.
227
+
228
+ ``` ruby
229
+ # 5.1 This is an example hash for updating/adding subfields.
230
+ tag_subfield_hash = { '245' => { 'b' => 'subtitle', 'a' => 'title' }, '336' => { 'a' => 'Audio' }, '246' => {'a' => nil}}
231
+
232
+ # if 245__$b existed, it will be replaced it with 'subtitle';
233
+ # otherwise, adding a new 245__$b subfield with value 'subtile';
234
+ # '246' => {'a' => nil}, since value is nil, it won't add/update 246__$a
235
+
236
+ # 5.2 This is an example array of removing fields.
237
+ fields_removal_list = [%w[856 4 1] %w[260 _ _]]
238
+
239
+ # Each item includes field information: [tag, indicator1, indictor2].
240
+ # if indicator is empty, using '_'
241
+
242
+ # How to use it:
243
+ # a. add/update subfields of existed fields in a TIND Marc record:
244
+ new_record = BerkeleyLibrary::TIND::Mapping::TindRecordUtil.update_record(record, tag_subfield_hash)
245
+ # b. remove a list of fields in a TIND Marc record:
246
+ new_record = BerkeleyLibrary::TIND::Mapping::TindRecordUtil.update_record(record, nil, fields_removal_list)
247
+ # c. both a. and b. :
248
+ new_record = BerkeleyLibrary::TIND::Mapping::TindRecordUtil.update_record(record, tag_subfield_hash, fields_removal_list)
249
+
250
+ ```
@@ -17,15 +17,15 @@ Gem::Specification.new do |spec|
17
17
  spec.homepage = BerkeleyLibrary::TIND::ModuleInfo::HOMEPAGE
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0")
20
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
20
  spec.require_paths = ['lib']
22
21
  spec.executables << 'tind-export'
23
22
 
24
23
  spec.required_ruby_version = ruby_version
25
24
 
25
+ spec.add_dependency 'berkeley_library-alma', '~> 0.0.1'
26
26
  spec.add_dependency 'berkeley_library-logging', '~> 0.2'
27
27
  spec.add_dependency 'berkeley_library-marc', '~> 0.3.0', '>= 0.3.1'
28
- spec.add_dependency 'berkeley_library-util', '~> 0.1'
28
+ spec.add_dependency 'berkeley_library-util', '~> 0.1', '>= 0.1.2'
29
29
  spec.add_dependency 'ice_nine', '~> 0.11'
30
30
  spec.add_dependency 'marc', '~> 1.0'
31
31
  spec.add_dependency 'rchardet', '~> 1.8'
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ # This should work if (1) the gem is installed, or
5
+ # (2) we're in development and used `bundle exec`
6
+ require 'berkeley_library/tind'
7
+ require 'berkeley_library/alma'
8
+ rescue LoadError
9
+ # If we're in development, `require 'bundler/setup'`
10
+ # is roughly equivalent to `bundle exec`
11
+ require 'bundler/setup'
12
+ require 'berkeley_library/tind'
13
+ require 'berkeley_library/alma'
14
+ end
15
+
16
+ def setup
17
+ # set collection name information
18
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.collection_parameter_hash = {
19
+ '336' => ['Image'],
20
+ '852' => ['East Asian Library'],
21
+ '980' => ['pre_1912'],
22
+ '982' => ['Pre 1912 Chinese Materials - short name', 'Pre 1912 Chinese Materials - long name'],
23
+ '991' => []
24
+ }
25
+
26
+ # flag: set it to true if using barcode getting Alma record; default is false
27
+ # BerkeleyLibrary::TIND::Mapping::AlmaBase.is_barcode = true
28
+ end
29
+
30
+ def additional_tind_fields
31
+ txt = 'v001_0064'
32
+ url = 'https://digitalassets.lib.berkeley.edu/pre1912ChineseMaterials/ucb/ready/991032333019706532/991032333019706532_v001_0064.jpg'
33
+ fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, txt)
34
+ datafields = [fft]
35
+
36
+ f_035 = BerkeleyLibrary::TIND::Mapping::TindField.f_035_from_alma_id('pre_1912', '991085821143406532')
37
+ datafields << f_035
38
+ end
39
+
40
+ ########### Use this, when creating multiple TIND records from a single Alma record ############
41
+ alma_id = '991085821143406532'
42
+ # alma_id = '99108582114340653' # a bad alma_id
43
+ # alma_id = '991084606989706532' # Host histrical record
44
+
45
+ setup
46
+
47
+ BerkeleyLibrary::Alma::Config.default!
48
+ alma_multiple_tind = BerkeleyLibrary::TIND::Mapping::AlmaMultipleTIND.new(alma_id)
49
+ tind_record = alma_multiple_tind.record(additional_tind_fields)
50
+ alma_multiple_tind.save_tind_record_to_file(tind_record, 'tmp/multiple.xml')
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ # This should work if (1) the gem is installed, or
5
+ # (2) we're in development and used `bundle exec`
6
+ require 'berkeley_library/tind'
7
+ require 'berkeley_library/alma'
8
+ rescue LoadError
9
+ # If we're in development, `require 'bundler/setup'`
10
+ # is roughly equivalent to `bundle exec`
11
+ require 'bundler/setup'
12
+ require 'berkeley_library/tind'
13
+ require 'berkeley_library/alma'
14
+ end
15
+
16
+ def setup
17
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.collection_parameter_hash = {
18
+ '336' => ['Image'],
19
+ '852' => ['East Asian Library'],
20
+ '980' => ['pre_1912'],
21
+ '982' => ['Pre 1912 Chinese Materials - short name', 'Pre 1912 Chinese Materials - long name'],
22
+ '991' => []
23
+ }
24
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.is_035_from_mms_id = true
25
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.is_barcode = false
26
+ end
27
+
28
+ def additional_tind_fields
29
+ txt = 'v001_0064'
30
+ url = 'https://digitalassets.lib.berkeley.edu/pre1912ChineseMaterials/ucb/ready/991032333019706532/991032333019706532_v001_0064.jpg'
31
+ fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, txt)
32
+ f = ::MARC::DataField.new('998', ' ', ' ', ['a', 'fake-value'])
33
+ [fft] << f
34
+ end
35
+
36
+ ############## Use this, when creating a TIND record from each Alma record ############
37
+ # alma_id = '991085821143406532'
38
+ # alma_id_bad = '99108582114340653' # a bad alma_id
39
+ # alma_id_not_qualified = '991084606989706532' # Host historical record
40
+ barcode = 'C084093187'
41
+
42
+ id = barcode
43
+ setup
44
+
45
+ BerkeleyLibrary::Alma::Config.default!
46
+ alma_single_tind = BerkeleyLibrary::TIND::Mapping::AlmaSingleTIND.new
47
+ tind_record = alma_single_tind.record(id, additional_tind_fields)
48
+ alma_single_tind.save_tind_record_to_file(id, tind_record, 'tmp/test_single.xml')
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ # This should work if (1) the gem is installed, or
5
+ # (2) we're in development and used `bundle exec`
6
+ require 'berkeley_library/tind'
7
+ require 'berkeley_library/alma'
8
+ rescue LoadError
9
+ # If we're in development, `require 'bundler/setup'`
10
+ # is roughly equivalent to `bundle exec`
11
+ require 'bundler/setup'
12
+ require 'berkeley_library/tind'
13
+ require 'berkeley_library/alma'
14
+ end
15
+
16
+ def setup
17
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.collection_parameter_hash = {
18
+ '336' => ['Image'],
19
+ '852' => ['Bioscience, Natural Resources & Public Health Library'],
20
+ '980' => ['Forestry'],
21
+ '982' => ['Forestry', 'Forestry'],
22
+ '991' => []
23
+ }
24
+
25
+ # BerkeleyLibrary::TIND::Mapping::AlmaBase.is_barcode = true
26
+ end
27
+
28
+ def fake_additional_tind_fields1
29
+ fields = []
30
+ txt = '001'
31
+ url = 'https://digitalassets.lib.berkeley.edu/forestry/ucb/images/b142086125_i180839998/b142086125_i180839998_001.jpg'
32
+ fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, txt)
33
+ f_998 = ::MARC::DataField.new('998', ' ', ' ', ['a', 'fake-value'])
34
+ f_035 = BerkeleyLibrary::TIND::Mapping::TindField.f_035('b142086125')
35
+ fields << f_998
36
+ fields << f_035
37
+ fields << fft
38
+ end
39
+
40
+ def fake_additional_tind_fields2
41
+ fields = []
42
+ txt = '002'
43
+ url = 'https://digitalassets.lib.berkeley.edu/forestry/ucb/images/b142086125_i180839998/b142086125_i180839998_002.jpg'
44
+ fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, txt)
45
+
46
+ f_998 = ::MARC::DataField.new('998', ' ', ' ', ['a', 'fake-value'])
47
+
48
+ f_035 = BerkeleyLibrary::TIND::Mapping::TindField.f_035('b142107827')
49
+ fields << f_998
50
+ fields << f_035
51
+ fields << fft
52
+ end
53
+
54
+ def tind_records
55
+ records = []
56
+ alma_tind = BerkeleyLibrary::TIND::Mapping::AlmaSingleTIND.new
57
+
58
+ record1 = alma_tind.record('b142086125', fake_additional_tind_fields1)
59
+ record2 = alma_tind.record('b142107827', fake_additional_tind_fields2)
60
+ records << record1
61
+ records << record2
62
+ end
63
+
64
+ def save_batch(file, with_tind_xmlwritter)
65
+ setup
66
+ writer = ::MARC::XMLWriter.new(file)
67
+ writer = BerkeleyLibrary::TIND::MARC::XMLWriter.new(file) if with_tind_xmlwritter
68
+
69
+ tind_records.each do |record|
70
+ record.leader = nil if with_tind_xmlwritter
71
+ writer.write(record)
72
+ end
73
+ writer.close
74
+ end
75
+
76
+ # save with tind xmlwritter
77
+ save_batch('tmp/test_tind_xmlwritter.xml', true)
78
+
79
+ # save with Marc xmlwritter
80
+ save_batch('tmp/test_marc_xmlwritter.xml', false)
data/bin/tind-marc ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ # This should work if (1) the gem is installed, or
5
+ # (2) we're in development and used `bundle exec`
6
+ require 'berkeley_library/tind'
7
+ require 'berkeley_library/alma'
8
+ rescue LoadError
9
+ # If we're in development, `require 'bundler/setup'`
10
+ # is roughly equivalent to `bundle exec`
11
+ require 'bundler/setup'
12
+ require 'berkeley_library/tind'
13
+ require 'berkeley_library/alma'
14
+ end
15
+
16
+ # 1. get Alma record
17
+ BerkeleyLibrary::Alma::Config.default!
18
+ # oskicat_num = 'b11082434'
19
+ # alma_num = '991011084939706532'
20
+ # alma no 880 field
21
+ alma_num = '991085821143406532'
22
+
23
+ # alma no 880 field
24
+ # alma_num = '991039355849706532'
25
+ record_id = BerkeleyLibrary::Alma::RecordId.parse(alma_num)
26
+ oskicat_record = record_id.get_marc_record
27
+
28
+ # 2. get collection information fields
29
+ # This information from "collection name" table on share driver
30
+ collection_parameters = {
31
+ '336' => ['Image'],
32
+ '852' => ['East Asian Library'],
33
+ '980' => ['pre_1912'],
34
+ '982' => ['Pre 1912 Chinese Materials', 'Pre 1912 Chinese Materials'],
35
+ '991' => []
36
+ }
37
+
38
+ collection_tind_fields = BerkeleyLibrary::TIND::Mapping::ExternalTindField.tind_fields_from_collection_information(collection_parameters)
39
+
40
+ # 3. get other external tind fields
41
+ other_external_tind_fields = []
42
+ tind_fields_from_alma_id = BerkeleyLibrary::TIND::Mapping::ExternalTindField.tind_mms_id_fields('991011084939706532')
43
+
44
+ other_external_tind_fields.concat tind_fields_from_alma_id
45
+
46
+ # 4. get fft fields
47
+
48
+ new_subfield1 = BerkeleyLibrary::TIND::Mapping::Util.subfield('a', 'https://digitalassets.lib.berkeley.edu/pre1912ChineseMaterials/ucb/ready/991032333019706532/991032333019706532_v001_0064.jpg')
49
+ new_subfield2 = BerkeleyLibrary::TIND::Mapping::Util.subfield('d', 'v001_0064')
50
+ fft_datafield = BerkeleyLibrary::TIND::Mapping::Util.datafield('FFT', [' ', ' '], [new_subfield1, new_subfield2])
51
+ ffts = [fft_datafield]
52
+
53
+ # 5. put all external tind fields together
54
+ external_tind_fields = collection_tind_fields
55
+ external_tind_fields.concat other_external_tind_fields
56
+ external_tind_fields.concat ffts
57
+
58
+ # 6. create tind-marc object,
59
+ tindmarc = BerkeleyLibrary::TIND::Mapping::TindMarc.new(oskicat_record)
60
+
61
+ # 7. add external tind fields(these tind fields will paticipate in "additional process")
62
+ tindmarc.tind_external_datafields = external_tind_fields
63
+
64
+ ##### output ####
65
+ # 8. Get tind fields mapped from alma
66
+ # tindmarc.tindfields
67
+
68
+ # 9. get a tind record which including external tind fields
69
+ # tindmarc.tind_record
70
+
71
+ # 10. save the tind record to an xml file
72
+
73
+ tindmarc.save('tmp/test.xml')
@@ -67,12 +67,10 @@ module BerkeleyLibrary
67
67
 
68
68
  def header_cell_style_for(col_index)
69
69
  @header_cell_styles ||= []
70
- @header_cell_styles[col_index] ||= begin
71
- find_or_create_cell_style(
72
- color: color_for(col_index),
73
- font_weight: 'bold'
74
- )
75
- end
70
+ @header_cell_styles[col_index] ||= find_or_create_cell_style(
71
+ color: color_for(col_index),
72
+ font_weight: 'bold'
73
+ )
76
74
  end
77
75
 
78
76
  def find_or_create_cell_style(color:, font_weight: nil, wrap: false)