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,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 Office
8
+ class Body < XML::ElementNode
9
+ def initialize(doc:)
10
+ super(:office, 'body', doc: doc)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,98 @@
1
+ require 'berkeley_library/util/ods/xml/namespace'
2
+ require 'berkeley_library/util/ods/xml/element_node'
3
+ require 'berkeley_library/util/ods/xml/table/table'
4
+ require 'berkeley_library/util/ods/xml/office/scripts'
5
+ require 'berkeley_library/util/ods/xml/office/font_face_decls'
6
+ require 'berkeley_library/util/ods/xml/office/automatic_styles'
7
+ require 'berkeley_library/util/ods/xml/office/body'
8
+ require 'berkeley_library/util/ods/xml/office/spreadsheet'
9
+
10
+ module BerkeleyLibrary
11
+ module Util
12
+ module ODS
13
+ module XML
14
+ module Office
15
+ class DocumentContent < XML::ElementNode
16
+
17
+ # ------------------------------------------------------------
18
+ # Constants
19
+
20
+ OFFICE_VERSION = '1.2'.freeze
21
+ REQUIRED_NAMESPACES = Namespace.reject { |ns| ns == Namespace::MANIFEST }
22
+
23
+ # ------------------------------------------------------------
24
+ # Initializer
25
+
26
+ def initialize(doc:)
27
+ super(:office, 'document-content', doc: doc)
28
+
29
+ set_default_attributes!
30
+ add_default_children!
31
+ end
32
+
33
+ # ------------------------------------------------------------
34
+ # Accessors and utility methods
35
+
36
+ def scripts
37
+ @scripts ||= Scripts.new(doc: doc)
38
+ end
39
+
40
+ def font_face_decls
41
+ @font_face_decls ||= Office::FontFaceDecls.new(doc: doc)
42
+ end
43
+
44
+ def automatic_styles
45
+ @automatic_styles ||= Office::AutomaticStyles.new(doc: doc)
46
+ end
47
+
48
+ def add_table(name, table_style = nil, protected: true)
49
+ new_table = XML::Table::Table.new(name, table_style, styles: automatic_styles, protected: protected)
50
+ new_table.tap { |table| spreadsheet.add_child(table) }
51
+ end
52
+
53
+ def spreadsheet
54
+ @spreadsheet ||= Office::Spreadsheet.new(doc: doc)
55
+ end
56
+
57
+ def body
58
+ @body ||= Body.new(doc: doc).tap { |body| body.add_child(spreadsheet) }
59
+ end
60
+
61
+ # ------------------------------------------------------------
62
+ # Protected methods
63
+
64
+ # ----------------------------------------
65
+ # Protected ElementNode overrides
66
+
67
+ protected
68
+
69
+ def create_element
70
+ # Make sure any styles, font faces, etc. needed for the body get created
71
+ # *before* we try to write them to XML
72
+ children.reverse_each(&:ensure_element!)
73
+
74
+ super
75
+ end
76
+
77
+ # ------------------------------------------------------------
78
+ # Private methods
79
+
80
+ private
81
+
82
+ def set_default_attributes!
83
+ REQUIRED_NAMESPACES.each { |ns| set_attribute(:xmlns, ns.prefix, ns.uri) }
84
+ set_attribute('version', OFFICE_VERSION)
85
+ end
86
+
87
+ def add_default_children!
88
+ children << scripts
89
+ children << font_face_decls
90
+ children << automatic_styles
91
+ children << body
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,39 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+ require 'berkeley_library/util/ods/xml/office/font_face_decls'
3
+ require 'berkeley_library/util/ods/xml/office/styles'
4
+
5
+ module BerkeleyLibrary
6
+ module Util
7
+ module ODS
8
+ module XML
9
+ module Office
10
+ class DocumentStyles < XML::ElementNode
11
+ REQUIRED_NAMESPACES = %i[office style fo].freeze
12
+
13
+ def initialize(doc:)
14
+ super(:office, 'document-styles', doc: doc)
15
+
16
+ set_default_attributes!
17
+ add_default_children!
18
+ end
19
+
20
+ private
21
+
22
+ def required_namespaces
23
+ @required_namespaces ||= REQUIRED_NAMESPACES.map { |p| Namespace.for_prefix(p) }
24
+ end
25
+
26
+ def set_default_attributes!
27
+ required_namespaces.each { |ns| set_attribute(:xmlns, ns.prefix, ns.uri) }
28
+ end
29
+
30
+ def add_default_children!
31
+ add_child(FontFaceDecls.new(doc: doc))
32
+ add_child(Styles.new(doc: doc))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+ require 'berkeley_library/util/ods/xml/style/font_face'
3
+
4
+ module BerkeleyLibrary
5
+ module Util
6
+ module ODS
7
+ module XML
8
+ module Office
9
+ class FontFaceDecls < XML::ElementNode
10
+ def initialize(doc:)
11
+ super(:office, 'font-face-decls', doc: doc)
12
+
13
+ add_font_face(default_face)
14
+ end
15
+
16
+ def add_font_face(font_face)
17
+ children << font_face
18
+ end
19
+
20
+ private
21
+
22
+ def default_face
23
+ Style::FontFace.default_face(doc: doc)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ 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 Office
8
+ class Scripts < XML::ElementNode
9
+ def initialize(doc:)
10
+ super(:office, 'scripts', doc: doc)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+ require 'berkeley_library/util/ods/xml/table/named_expressions'
3
+
4
+ module BerkeleyLibrary
5
+ module Util
6
+ module ODS
7
+ module XML
8
+ module Office
9
+ class Spreadsheet < XML::ElementNode
10
+ def initialize(doc:)
11
+ super(:office, 'spreadsheet', doc: doc)
12
+ end
13
+
14
+ def named_expressions
15
+ @named_expressions ||= Table::NamedExpressions.new(doc: doc)
16
+ end
17
+
18
+ def add_child(child)
19
+ other_children << child
20
+ end
21
+
22
+ def children
23
+ other_children.dup.tap { |cc| cc << named_expressions }
24
+ end
25
+
26
+ private
27
+
28
+ def other_children
29
+ @other_children ||= []
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ require 'berkeley_library/util/ods/xml/element_node'
2
+ require 'berkeley_library/util/ods/xml/style/style'
3
+ require 'berkeley_library/util/ods/xml/style/default_style'
4
+ require 'berkeley_library/util/ods/xml/style/paragraph_properties'
5
+
6
+ module BerkeleyLibrary
7
+ module Util
8
+ module ODS
9
+ module XML
10
+ module Office
11
+ class Styles < XML::ElementNode
12
+ def initialize(doc:)
13
+ super(:office, 'styles', doc: doc)
14
+
15
+ add_default_children!
16
+ end
17
+
18
+ private
19
+
20
+ def add_default_children!
21
+ add_child(table_cell_default_style)
22
+ add_child(Style::Style.new('Default', 'table-cell', doc: doc))
23
+ end
24
+
25
+ def table_cell_default_style
26
+ style_children = [
27
+ Style::ParagraphProperties.new(doc: doc),
28
+ Style::TextProperties.new(font_name: Style::FontFace::DEFAULT_FONT_FACE, doc: doc)
29
+ ]
30
+ Style::DefaultStyle.new('table-cell', doc: doc).tap do |ds|
31
+ style_children.each { |c| ds.add_child(c) }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,58 @@
1
+ require 'berkeley_library/util/ods/xml/style/style'
2
+ require 'berkeley_library/util/ods/xml/style/table_cell_properties'
3
+ require 'berkeley_library/util/ods/xml/style/text_properties'
4
+
5
+ module BerkeleyLibrary
6
+ module Util
7
+ module ODS
8
+ module XML
9
+ module Style
10
+ class CellStyle < Style
11
+
12
+ attr_reader :color, :font_weight
13
+
14
+ # Initializes a new cell style. Note that this should not be called
15
+ # directly, but only from {XML::Office::AutomaticStyles#add_cell_style}.
16
+ #
17
+ # @param name [String] the style name
18
+ # @param color [String, nil] a hex color (e.g. `#fdb515`)
19
+ # @param font_weight [String, nil] the font weight, if other than normal
20
+ # @param wrap [Boolean] whether to allow text wrapping
21
+ # @param styles [XML::Office::AutomaticStyles] the document styles
22
+ # rubocop:disable Metrics/ParameterLists, Style/OptionalBooleanParameter
23
+ def initialize(name, protected = false, color = nil, styles:, font_weight: nil, wrap: false)
24
+ super(name, :table_cell, doc: styles.doc)
25
+ @protected = protected
26
+ @color = color
27
+ @font_weight = font_weight
28
+ @wrap = wrap
29
+
30
+ set_attribute('parent-style-name', 'Default')
31
+ add_default_children!
32
+ end
33
+ # rubocop:enable Metrics/ParameterLists, Style/OptionalBooleanParameter
34
+
35
+ def protected?
36
+ @protected
37
+ end
38
+
39
+ def wrap?
40
+ @wrap
41
+ end
42
+
43
+ def custom_text_properties?
44
+ [color, font_weight].any? { |p| !p.nil? }
45
+ end
46
+
47
+ private
48
+
49
+ def add_default_children!
50
+ children << TableCellProperties.new(protected?, wrap: wrap?, doc: doc)
51
+ children << TextProperties.new(color: color, font_weight: font_weight, doc: doc) if custom_text_properties?
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,36 @@
1
+ require 'berkeley_library/util/ods/xml/style/style'
2
+ require 'berkeley_library/util/ods/xml/style/table_column_properties'
3
+
4
+ module BerkeleyLibrary
5
+ module Util
6
+ module ODS
7
+ module XML
8
+ module Style
9
+ class ColumnStyle < Style
10
+ DEFAULT_WIDTH = '1in'.freeze
11
+
12
+ attr_reader :width
13
+
14
+ # Initializes a new column style. Note that this should not be called
15
+ # directly, but only from {XML::Office::AutomaticStyles#add_column_style}.
16
+ #
17
+ # @param style_name [String] the name of the style
18
+ # @param width [String] the column width
19
+ # @param styles [XML::Office::AutomaticStyles] the document styles
20
+ def initialize(style_name, width = nil, styles:)
21
+ super(style_name, :table_column, doc: styles.doc)
22
+ @width = width || DEFAULT_WIDTH
23
+ add_default_children!
24
+ end
25
+
26
+ private
27
+
28
+ def add_default_children!
29
+ children << TableColumnProperties.new(width, doc: doc)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
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 DefaultStyle < XML::ElementNode
10
+
11
+ attr_reader :family
12
+
13
+ def initialize(family, doc:)
14
+ super(:style, 'default-style', doc: doc)
15
+
16
+ @family = Family.ensure_family(family)
17
+
18
+ set_default_attributes!
19
+ end
20
+
21
+ private
22
+
23
+ def set_default_attributes!
24
+ set_attribute('family', family)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,85 @@
1
+ require 'typesafe_enum'
2
+
3
+ module BerkeleyLibrary
4
+ module Util
5
+ module ODS
6
+ module XML
7
+ module Style
8
+ class Family < TypesafeEnum::Base
9
+ # ------------------------------------------------------------
10
+ # Enum instances
11
+
12
+ # NOTE: declaration order is as they appear in spreadsheets saved from LibreOffice
13
+
14
+ new(:TABLE_COLUMN, 'table-column') do
15
+ def prefix
16
+ 'co'
17
+ end
18
+ end
19
+
20
+ new(:TABLE_ROW, 'table-row') do
21
+ def prefix
22
+ 'ro'
23
+ end
24
+ end
25
+
26
+ new(:TABLE, 'table') do
27
+ def prefix
28
+ 'ta'
29
+ end
30
+ end
31
+
32
+ new(:TABLE_CELL, 'table-cell') do
33
+ def prefix
34
+ 'ce'
35
+ end
36
+ end
37
+
38
+ # ------------------------------------------------------------
39
+ # Class methods
40
+
41
+ class << self
42
+ def from_string(str)
43
+ find_by_key(str.to_s.upcase.to_sym) ||
44
+ find_by_value_str(str.to_s.downcase)
45
+ end
46
+
47
+ def ensure_family(f)
48
+ family = f.is_a?(Family) ? f : Family.from_string(f)
49
+ return family if family
50
+
51
+ raise ArgumentError, "Not a style family: #{f.inspect}"
52
+ end
53
+ end
54
+
55
+ # ------------------------------------------------------------
56
+ # Public instance methods
57
+
58
+ def split_name(style_name)
59
+ return [nil, style_name] unless style_name.start_with?(prefix)
60
+
61
+ [prefix, style_name[prefix.size..]]
62
+ end
63
+
64
+ def index_part(style_name)
65
+ prefix, suffix = split_name(style_name)
66
+ return unless prefix == self.prefix
67
+ return unless (suffix_i = suffix.to_i).to_s == suffix
68
+
69
+ suffix_i
70
+ end
71
+
72
+ # ------------------------------------------------------------
73
+ # TypesafeEnum overrides
74
+
75
+ def to_s
76
+ # noinspection RubyYardReturnMatch
77
+ value
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end