berkeley_library-tind 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/build.yml +18 -0
  3. data/.gitignore +388 -0
  4. data/.idea/inspectionProfiles/Project_Default.xml +20 -0
  5. data/.idea/misc.xml +4 -0
  6. data/.idea/modules.xml +8 -0
  7. data/.idea/tind.iml +138 -0
  8. data/.idea/vcs.xml +6 -0
  9. data/.rubocop.yml +334 -0
  10. data/.ruby-version +1 -0
  11. data/.simplecov +8 -0
  12. data/.yardopts +1 -0
  13. data/CHANGES.md +58 -0
  14. data/Dockerfile +57 -0
  15. data/Gemfile +3 -0
  16. data/Jenkinsfile +18 -0
  17. data/LICENSE.md +21 -0
  18. data/README.md +73 -0
  19. data/Rakefile +20 -0
  20. data/berkeley_library-tind.gemspec +50 -0
  21. data/bin/tind-export +14 -0
  22. data/docker-compose.yml +15 -0
  23. data/lib/berkeley_library/tind.rb +3 -0
  24. data/lib/berkeley_library/tind/api.rb +1 -0
  25. data/lib/berkeley_library/tind/api/api.rb +132 -0
  26. data/lib/berkeley_library/tind/api/api_exception.rb +131 -0
  27. data/lib/berkeley_library/tind/api/collection.rb +82 -0
  28. data/lib/berkeley_library/tind/api/date_range.rb +67 -0
  29. data/lib/berkeley_library/tind/api/format.rb +32 -0
  30. data/lib/berkeley_library/tind/api/search.rb +100 -0
  31. data/lib/berkeley_library/tind/config.rb +103 -0
  32. data/lib/berkeley_library/tind/export.rb +1 -0
  33. data/lib/berkeley_library/tind/export/column.rb +54 -0
  34. data/lib/berkeley_library/tind/export/column_group.rb +144 -0
  35. data/lib/berkeley_library/tind/export/column_group_list.rb +131 -0
  36. data/lib/berkeley_library/tind/export/column_width_calculator.rb +76 -0
  37. data/lib/berkeley_library/tind/export/config.rb +154 -0
  38. data/lib/berkeley_library/tind/export/csv_exporter.rb +29 -0
  39. data/lib/berkeley_library/tind/export/export.rb +47 -0
  40. data/lib/berkeley_library/tind/export/export_command.rb +168 -0
  41. data/lib/berkeley_library/tind/export/export_exception.rb +8 -0
  42. data/lib/berkeley_library/tind/export/export_format.rb +67 -0
  43. data/lib/berkeley_library/tind/export/exporter.rb +105 -0
  44. data/lib/berkeley_library/tind/export/filter.rb +52 -0
  45. data/lib/berkeley_library/tind/export/no_results_error.rb +7 -0
  46. data/lib/berkeley_library/tind/export/ods_exporter.rb +138 -0
  47. data/lib/berkeley_library/tind/export/row.rb +24 -0
  48. data/lib/berkeley_library/tind/export/row_metrics.rb +18 -0
  49. data/lib/berkeley_library/tind/export/table.rb +175 -0
  50. data/lib/berkeley_library/tind/export/table_metrics.rb +116 -0
  51. data/lib/berkeley_library/tind/marc.rb +1 -0
  52. data/lib/berkeley_library/tind/marc/xml_reader.rb +144 -0
  53. data/lib/berkeley_library/tind/module_info.rb +14 -0
  54. data/lib/berkeley_library/util/arrays.rb +178 -0
  55. data/lib/berkeley_library/util/logging.rb +1 -0
  56. data/lib/berkeley_library/util/ods/spreadsheet.rb +170 -0
  57. data/lib/berkeley_library/util/ods/xml/content_doc.rb +26 -0
  58. data/lib/berkeley_library/util/ods/xml/document_node.rb +57 -0
  59. data/lib/berkeley_library/util/ods/xml/element_node.rb +106 -0
  60. data/lib/berkeley_library/util/ods/xml/loext/table_protection.rb +26 -0
  61. data/lib/berkeley_library/util/ods/xml/manifest/file_entry.rb +42 -0
  62. data/lib/berkeley_library/util/ods/xml/manifest/manifest.rb +73 -0
  63. data/lib/berkeley_library/util/ods/xml/manifest_doc.rb +26 -0
  64. data/lib/berkeley_library/util/ods/xml/namespace.rb +46 -0
  65. data/lib/berkeley_library/util/ods/xml/office/automatic_styles.rb +181 -0
  66. data/lib/berkeley_library/util/ods/xml/office/body.rb +17 -0
  67. data/lib/berkeley_library/util/ods/xml/office/document_content.rb +98 -0
  68. data/lib/berkeley_library/util/ods/xml/office/document_styles.rb +39 -0
  69. data/lib/berkeley_library/util/ods/xml/office/font_face_decls.rb +30 -0
  70. data/lib/berkeley_library/util/ods/xml/office/scripts.rb +17 -0
  71. data/lib/berkeley_library/util/ods/xml/office/spreadsheet.rb +37 -0
  72. data/lib/berkeley_library/util/ods/xml/office/styles.rb +39 -0
  73. data/lib/berkeley_library/util/ods/xml/style/cell_style.rb +58 -0
  74. data/lib/berkeley_library/util/ods/xml/style/column_style.rb +36 -0
  75. data/lib/berkeley_library/util/ods/xml/style/default_style.rb +31 -0
  76. data/lib/berkeley_library/util/ods/xml/style/family.rb +85 -0
  77. data/lib/berkeley_library/util/ods/xml/style/font_face.rb +46 -0
  78. data/lib/berkeley_library/util/ods/xml/style/paragraph_properties.rb +30 -0
  79. data/lib/berkeley_library/util/ods/xml/style/row_style.rb +37 -0
  80. data/lib/berkeley_library/util/ods/xml/style/style.rb +44 -0
  81. data/lib/berkeley_library/util/ods/xml/style/table_cell_properties.rb +40 -0
  82. data/lib/berkeley_library/util/ods/xml/style/table_column_properties.rb +30 -0
  83. data/lib/berkeley_library/util/ods/xml/style/table_properties.rb +25 -0
  84. data/lib/berkeley_library/util/ods/xml/style/table_row_properties.rb +28 -0
  85. data/lib/berkeley_library/util/ods/xml/style/table_style.rb +27 -0
  86. data/lib/berkeley_library/util/ods/xml/style/text_properties.rb +52 -0
  87. data/lib/berkeley_library/util/ods/xml/styles_doc.rb +26 -0
  88. data/lib/berkeley_library/util/ods/xml/table/named_expressions.rb +17 -0
  89. data/lib/berkeley_library/util/ods/xml/table/repeatable.rb +38 -0
  90. data/lib/berkeley_library/util/ods/xml/table/table.rb +193 -0
  91. data/lib/berkeley_library/util/ods/xml/table/table_cell.rb +46 -0
  92. data/lib/berkeley_library/util/ods/xml/table/table_column.rb +43 -0
  93. data/lib/berkeley_library/util/ods/xml/table/table_row.rb +136 -0
  94. data/lib/berkeley_library/util/ods/xml/text/p.rb +118 -0
  95. data/lib/berkeley_library/util/paths.rb +111 -0
  96. data/lib/berkeley_library/util/stringios.rb +30 -0
  97. data/lib/berkeley_library/util/strings.rb +42 -0
  98. data/lib/berkeley_library/util/sys_exits.rb +15 -0
  99. data/lib/berkeley_library/util/times.rb +22 -0
  100. data/lib/berkeley_library/util/uris.rb +44 -0
  101. data/lib/berkeley_library/util/uris/appender.rb +162 -0
  102. data/lib/berkeley_library/util/uris/requester.rb +62 -0
  103. data/lib/berkeley_library/util/uris/validator.rb +32 -0
  104. data/rakelib/bundle.rake +8 -0
  105. data/rakelib/coverage.rake +11 -0
  106. data/rakelib/gem.rake +54 -0
  107. data/rakelib/rubocop.rake +18 -0
  108. data/rakelib/spec.rake +2 -0
  109. data/spec/.rubocop.yml +40 -0
  110. data/spec/berkeley_library/tind/api/api_exception_spec.rb +91 -0
  111. data/spec/berkeley_library/tind/api/api_spec.rb +143 -0
  112. data/spec/berkeley_library/tind/api/collection_spec.rb +74 -0
  113. data/spec/berkeley_library/tind/api/date_range_spec.rb +110 -0
  114. data/spec/berkeley_library/tind/api/format_spec.rb +54 -0
  115. data/spec/berkeley_library/tind/api/search_spec.rb +364 -0
  116. data/spec/berkeley_library/tind/config_spec.rb +86 -0
  117. data/spec/berkeley_library/tind/export/column_group_spec.rb +29 -0
  118. data/spec/berkeley_library/tind/export/column_spec.rb +43 -0
  119. data/spec/berkeley_library/tind/export/config_spec.rb +206 -0
  120. data/spec/berkeley_library/tind/export/export_command_spec.rb +169 -0
  121. data/spec/berkeley_library/tind/export/export_format_spec.rb +59 -0
  122. data/spec/berkeley_library/tind/export/export_matcher.rb +112 -0
  123. data/spec/berkeley_library/tind/export/export_spec.rb +150 -0
  124. data/spec/berkeley_library/tind/export/exporter_spec.rb +125 -0
  125. data/spec/berkeley_library/tind/export/row_spec.rb +118 -0
  126. data/spec/berkeley_library/tind/export/table_spec.rb +322 -0
  127. data/spec/berkeley_library/tind/marc/xml_reader_spec.rb +93 -0
  128. data/spec/berkeley_library/util/arrays_spec.rb +340 -0
  129. data/spec/berkeley_library/util/ods/spreadsheet_spec.rb +124 -0
  130. data/spec/berkeley_library/util/ods/xml/content_doc_spec.rb +121 -0
  131. data/spec/berkeley_library/util/ods/xml/manifest/file_entry_spec.rb +27 -0
  132. data/spec/berkeley_library/util/ods/xml/manifest/manifest_spec.rb +33 -0
  133. data/spec/berkeley_library/util/ods/xml/office/document_content_spec.rb +60 -0
  134. data/spec/berkeley_library/util/ods/xml/style/automatic_styles_spec.rb +37 -0
  135. data/spec/berkeley_library/util/ods/xml/style/family_spec.rb +57 -0
  136. data/spec/berkeley_library/util/ods/xml/table/table_row_spec.rb +179 -0
  137. data/spec/berkeley_library/util/ods/xml/table/table_spec.rb +218 -0
  138. data/spec/berkeley_library/util/paths_spec.rb +90 -0
  139. data/spec/berkeley_library/util/stringios_spec.rb +34 -0
  140. data/spec/berkeley_library/util/strings_spec.rb +27 -0
  141. data/spec/berkeley_library/util/times_spec.rb +39 -0
  142. data/spec/berkeley_library/util/uris_spec.rb +118 -0
  143. data/spec/data/collection-names.txt +438 -0
  144. data/spec/data/collections.json +4827 -0
  145. data/spec/data/disjoint-records.xml +187 -0
  146. data/spec/data/record-184453.xml +58 -0
  147. data/spec/data/record-184458.xml +63 -0
  148. data/spec/data/record-187888.xml +78 -0
  149. data/spec/data/records-api-search-cjk-p1.xml +6381 -0
  150. data/spec/data/records-api-search-cjk-p2.xml +5 -0
  151. data/spec/data/records-api-search-p1.xml +4506 -0
  152. data/spec/data/records-api-search-p2.xml +4509 -0
  153. data/spec/data/records-api-search-p3.xml +4506 -0
  154. data/spec/data/records-api-search-p4.xml +4509 -0
  155. data/spec/data/records-api-search-p5.xml +4506 -0
  156. data/spec/data/records-api-search-p6.xml +2436 -0
  157. data/spec/data/records-api-search-p7.xml +5 -0
  158. data/spec/data/records-api-search.xml +234 -0
  159. data/spec/data/records-manual-search.xml +547 -0
  160. data/spec/spec_helper.rb +30 -0
  161. data/test/profile/table_from_records_profile.rb +46 -0
  162. metadata +585 -0
@@ -0,0 +1,46 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class FontFace < XML::ElementNode
9
+ DEFAULT_FONT_FACE = 'Liberation Sans'.freeze
10
+
11
+ attr_reader :name, :svg_family, :family_generic, :font_pitch
12
+
13
+ def initialize(name, doc:, svg_family: nil, family_generic: nil, font_pitch: nil)
14
+ super(:style, 'font-face', doc: doc)
15
+
16
+ set_attribute('name', name)
17
+ set_attribute(:svg, 'font-family', svg_family || to_family(name))
18
+ set_attribute('font-family-generic', family_generic) if family_generic
19
+ set_attribute('font-pitch', font_pitch) if font_pitch
20
+ end
21
+
22
+ class << self
23
+ def default_face(doc:)
24
+ FontFace.new(FontFace::DEFAULT_FONT_FACE, family_generic: 'swiss', font_pitch: 'variable', doc: doc)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def to_family(name)
31
+ # TODO: https://www.w3.org/TR/CSS2/syndata.html#value-def-identifier
32
+ name =~ /^[[:alpha:]][[:alnum:]]*$/ ? name : quote_name(name)
33
+ end
34
+
35
+ def quote_name(name)
36
+ return name.inspect if name.include?("'")
37
+
38
+ "'#{name}'"
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class ParagraphProperties < ElementNode
9
+
10
+ DEFAULT_TAB_STOP_DISTANCE = '0.5in'.freeze
11
+
12
+ attr_reader :tab_stop_distance
13
+
14
+ def initialize(tab_stop_distance = DEFAULT_TAB_STOP_DISTANCE, doc:)
15
+ super(:style, 'paragraph-properties', doc: doc)
16
+ @tab_stop_distance = tab_stop_distance
17
+ set_default_attributes!
18
+ end
19
+
20
+ private
21
+
22
+ def set_default_attributes!
23
+ set_attribute('tab-stop-distance', tab_stop_distance)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ require 'berkeley_library/util/ods/xml/style/style'
2
+ require 'berkeley_library/util/ods/xml/style/table_row_properties'
3
+
4
+ module BerkeleyLibrary
5
+ module Util
6
+ module ODS
7
+ module XML
8
+ module Style
9
+ class RowStyle < Style
10
+
11
+ DEFAULT_HEIGHT = '0.25in'.freeze
12
+
13
+ attr_reader :height
14
+
15
+ # Initializes a new cell style. Note that this should not be called
16
+ # directly, but only from {XML::Office::AutomaticStyles#add_row_style}.
17
+ #
18
+ # @param name [String] the name of the style
19
+ # @param height [String] the row height
20
+ # @param styles [XML::Office::AutomaticStyles] the document styles
21
+ def initialize(name, height = nil, styles:)
22
+ super(name, :table_row, doc: styles.doc)
23
+ @height = height || DEFAULT_HEIGHT
24
+ add_default_children!
25
+ end
26
+
27
+ private
28
+
29
+ def add_default_children!
30
+ children << TableRowProperties.new(height, doc: doc)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+ require 'berkeley_library/util/ods/xml/style/family'
3
+
4
+ module BerkeleyLibrary
5
+ module Util
6
+ module ODS
7
+ module XML
8
+ module Style
9
+ class Style < XML::ElementNode
10
+ include Comparable
11
+
12
+ attr_reader :style_name, :family
13
+
14
+ def initialize(style_name, family, doc:)
15
+ super(:style, 'style', doc: doc)
16
+
17
+ @style_name = style_name
18
+ @family = Family.ensure_family(family)
19
+
20
+ set_default_attributes!
21
+ end
22
+
23
+ def <=>(other)
24
+ return 0 if other.equal?(self)
25
+ return nil unless other.instance_of?(self.class)
26
+
27
+ s_index, o_index = [style_name, other.style_name].map { |n| family.index_part(n) }
28
+ return style_name <=> other.style_name unless s_index && o_index
29
+
30
+ s_index <=> o_index
31
+ end
32
+
33
+ private
34
+
35
+ def set_default_attributes!
36
+ set_attribute('name', style_name)
37
+ set_attribute('family', family)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class TableCellProperties < ElementNode
9
+
10
+ # rubocop:disable Style/KeywordParametersOrder
11
+ def initialize(protected, wrap: false, doc:)
12
+ super(:style, 'table-cell-properties', doc: doc)
13
+ @protected = protected
14
+ @wrap = wrap
15
+ set_default_attributes!
16
+ end
17
+ # rubocop:enable Style/KeywordParametersOrder
18
+
19
+ def protected?
20
+ @protected
21
+ end
22
+
23
+ def wrap?
24
+ @wrap
25
+ end
26
+
27
+ private
28
+
29
+ def set_default_attributes!
30
+ set_attribute(:style, 'cell-protect', protected? ? 'protected' : 'none')
31
+ set_attribute(:style, 'vertical-align', 'top')
32
+ set_attribute('print-content', 'true')
33
+ set_attribute(:fo, 'wrap-option', 'wrap') if wrap?
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class TableRowProperties < ElementNode
9
+ attr_reader :height
10
+
11
+ def initialize(height, doc:)
12
+ super(:style, 'table-row-properties', doc: doc)
13
+ @height = height
14
+
15
+ set_default_attributes!
16
+ end
17
+
18
+ private
19
+
20
+ def set_default_attributes!
21
+ set_attribute('row-height', height)
22
+ set_attribute(:fo, 'break-before', 'auto')
23
+ set_attribute('use-optimal-row-height', 'true')
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class TableProperties < ElementNode
9
+ def initialize(doc:)
10
+ super(:style, 'table-properties', doc: doc)
11
+ set_default_attributes!
12
+ end
13
+
14
+ private
15
+
16
+ def set_default_attributes!
17
+ set_attribute(:table, 'display', 'true')
18
+ set_attribute('writing-mode', 'lr-tb')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class TableColumnProperties < ElementNode
9
+ attr_reader :width
10
+
11
+ def initialize(width, doc:)
12
+ super(:style, 'table-column-properties', doc: doc)
13
+ @width = width
14
+ set_default_attributes!
15
+ end
16
+
17
+ private
18
+
19
+ def set_default_attributes!
20
+ set_attribute(:fo, 'break-before', 'auto')
21
+ set_attribute('column-width', width)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'berkeley_library/util/ods/xml/style/style'
2
+ require 'berkeley_library/util/ods/xml/style/family'
3
+ require 'berkeley_library/util/ods/xml/style/table_properties'
4
+
5
+ module BerkeleyLibrary
6
+ module Util
7
+ module ODS
8
+ module XML
9
+ module Style
10
+ class TableStyle < Style
11
+ # Initializes a new table style. Note that this should not be called
12
+ # directly, but only from {XML::Office::AutomaticStyles#add_table_style}.
13
+ #
14
+ # @param name [String] the name of the style
15
+ # @param styles [XML::Office::AutomaticStyles] the document styles
16
+ def initialize(name, styles:)
17
+ super(name, :table, doc: styles.doc)
18
+
19
+ set_attribute('master-page-name', 'Default')
20
+ children << TableProperties.new(doc: doc)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,52 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class TextProperties < ElementNode
9
+
10
+ FONT_WEIGHT_ATTRS = %w[font-weight font-weight-asian font-weight-complex].freeze
11
+ COLOR_RE = /^#[[:xdigit:]]{6}$/.freeze
12
+
13
+ attr_reader :color, :font_name, :language, :country, :font_weight
14
+
15
+ # rubocop:disable Metrics/ParameterLists, Style/KeywordParametersOrder
16
+ def initialize(color: nil, font_name: nil, font_weight: nil, language: 'en', country: 'US', doc:)
17
+ super(:style, 'text-properties', doc: doc)
18
+ @color = ensure_color(color)
19
+ @font_name = font_name
20
+ @language = language
21
+ @country = country
22
+ @font_weight = font_weight
23
+ set_default_attributes!
24
+ end
25
+ # rubocop:enable Metrics/ParameterLists, Style/KeywordParametersOrder
26
+
27
+ private
28
+
29
+ def set_default_attributes!
30
+ set_attribute('font-name', font_name) if font_name
31
+ set_attribute(:fo, 'language', language) if language
32
+ set_attribute(:fo, 'country', country) if country
33
+ set_attribute(:fo, 'color', color) if color
34
+ set_font_weight_attributes!
35
+ end
36
+
37
+ def set_font_weight_attributes!
38
+ FONT_WEIGHT_ATTRS.each { |attr| set_attribute(:fo, attr, font_weight) } if font_weight
39
+ end
40
+
41
+ def ensure_color(color)
42
+ return unless color
43
+ raise ArgumentError, "Not a valid hex color: #{color.inspect}" unless color =~ COLOR_RE
44
+
45
+ color.downcase
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ require 'nokogiri'
2
+ require 'berkeley_library/util/ods/xml/document_node'
3
+ require 'berkeley_library/util/ods/xml/office/document_styles'
4
+
5
+ module BerkeleyLibrary
6
+ module Util
7
+ module ODS
8
+ module XML
9
+ class StylesDoc < DocumentNode
10
+
11
+ def initialize
12
+ super('styles.xml')
13
+ end
14
+
15
+ def root_element_node
16
+ document_styles
17
+ end
18
+
19
+ def document_styles
20
+ @document_styles ||= Office::DocumentStyles.new(doc: doc)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Table
8
+ class NamedExpressions < XML::ElementNode
9
+ def initialize(doc:)
10
+ super(:table, 'named-expressions', doc: doc)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ module BerkeleyLibrary
2
+ module Util
3
+ module ODS
4
+ module XML
5
+ module Table
6
+ class Repeatable < XML::ElementNode
7
+
8
+ attr_reader :table, :attr_name_num_repeated, :number_repeated
9
+
10
+ def initialize(name, attr_name_num_repeated, number_repeated, table:)
11
+ super(:table, name, doc: table.doc)
12
+ @table = table
13
+ @attr_name_num_repeated = attr_name_num_repeated
14
+ self.number_repeated = number_repeated
15
+ end
16
+
17
+ def number_repeated=(value)
18
+ raise ArgumentError, "Invalid number of repeats: #{value.inspect} => #{value.to_i}" if (repeats = value.to_i) <= 0
19
+
20
+ if repeats == 1
21
+ clear_attribute(attr_name_num_repeated)
22
+ else
23
+ set_attribute(attr_name_num_repeated, repeats)
24
+ end
25
+
26
+ @number_repeated = repeats
27
+ end
28
+
29
+ def increment_repeats!
30
+ self.number_repeated += 1
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end