caracal_the_curve 1.4.1

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.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +22 -0
  3. data/.github/workflows/publish_gem.yml +40 -0
  4. data/.gitignore +25 -0
  5. data/.travis.yml +20 -0
  6. data/CHANGELOG.md +141 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +842 -0
  10. data/Rakefile +7 -0
  11. data/caracal.gemspec +28 -0
  12. data/lib/caracal/core/bookmarks.rb +52 -0
  13. data/lib/caracal/core/custom_properties.rb +49 -0
  14. data/lib/caracal/core/file_name.rb +43 -0
  15. data/lib/caracal/core/fonts.rb +75 -0
  16. data/lib/caracal/core/iframes.rb +42 -0
  17. data/lib/caracal/core/ignorables.rb +47 -0
  18. data/lib/caracal/core/images.rb +37 -0
  19. data/lib/caracal/core/list_styles.rb +93 -0
  20. data/lib/caracal/core/lists.rb +57 -0
  21. data/lib/caracal/core/models/base_model.rb +51 -0
  22. data/lib/caracal/core/models/bookmark_model.rb +86 -0
  23. data/lib/caracal/core/models/border_model.rb +120 -0
  24. data/lib/caracal/core/models/custom_property_model.rb +60 -0
  25. data/lib/caracal/core/models/font_model.rb +64 -0
  26. data/lib/caracal/core/models/iframe_model.rb +148 -0
  27. data/lib/caracal/core/models/image_model.rb +133 -0
  28. data/lib/caracal/core/models/line_break_model.rb +15 -0
  29. data/lib/caracal/core/models/link_model.rb +94 -0
  30. data/lib/caracal/core/models/list_item_model.rb +108 -0
  31. data/lib/caracal/core/models/list_model.rb +132 -0
  32. data/lib/caracal/core/models/list_style_model.rb +118 -0
  33. data/lib/caracal/core/models/margin_model.rb +76 -0
  34. data/lib/caracal/core/models/namespace_model.rb +65 -0
  35. data/lib/caracal/core/models/page_break_model.rb +61 -0
  36. data/lib/caracal/core/models/page_number_model.rb +95 -0
  37. data/lib/caracal/core/models/page_size_model.rb +79 -0
  38. data/lib/caracal/core/models/paragraph_model.rb +186 -0
  39. data/lib/caracal/core/models/relationship_model.rb +114 -0
  40. data/lib/caracal/core/models/rule_model.rb +27 -0
  41. data/lib/caracal/core/models/style_model.rb +165 -0
  42. data/lib/caracal/core/models/table_cell_model.rb +176 -0
  43. data/lib/caracal/core/models/table_model.rb +206 -0
  44. data/lib/caracal/core/models/text_model.rb +118 -0
  45. data/lib/caracal/core/namespaces.rb +89 -0
  46. data/lib/caracal/core/page_breaks.rb +29 -0
  47. data/lib/caracal/core/page_numbers.rb +58 -0
  48. data/lib/caracal/core/page_settings.rb +74 -0
  49. data/lib/caracal/core/relationships.rb +90 -0
  50. data/lib/caracal/core/rules.rb +35 -0
  51. data/lib/caracal/core/styles.rb +86 -0
  52. data/lib/caracal/core/tables.rb +42 -0
  53. data/lib/caracal/core/text.rb +75 -0
  54. data/lib/caracal/document.rb +272 -0
  55. data/lib/caracal/errors.rb +23 -0
  56. data/lib/caracal/renderers/app_renderer.rb +41 -0
  57. data/lib/caracal/renderers/content_types_renderer.rb +54 -0
  58. data/lib/caracal/renderers/core_renderer.rb +44 -0
  59. data/lib/caracal/renderers/custom_renderer.rb +64 -0
  60. data/lib/caracal/renderers/document_renderer.rb +427 -0
  61. data/lib/caracal/renderers/fonts_renderer.rb +56 -0
  62. data/lib/caracal/renderers/footer_renderer.rb +90 -0
  63. data/lib/caracal/renderers/numbering_renderer.rb +88 -0
  64. data/lib/caracal/renderers/package_relationships_renderer.rb +51 -0
  65. data/lib/caracal/renderers/relationships_renderer.rb +48 -0
  66. data/lib/caracal/renderers/settings_renderer.rb +58 -0
  67. data/lib/caracal/renderers/styles_renderer.rb +181 -0
  68. data/lib/caracal/renderers/xml_renderer.rb +83 -0
  69. data/lib/caracal/utilities.rb +23 -0
  70. data/lib/caracal/version.rb +3 -0
  71. data/lib/caracal.rb +40 -0
  72. data/lib/tilt/caracal.rb +21 -0
  73. data/spec/lib/caracal/core/bookmarks_spec.rb +35 -0
  74. data/spec/lib/caracal/core/file_name_spec.rb +54 -0
  75. data/spec/lib/caracal/core/fonts_spec.rb +119 -0
  76. data/spec/lib/caracal/core/iframes_spec.rb +29 -0
  77. data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
  78. data/spec/lib/caracal/core/images_spec.rb +25 -0
  79. data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
  80. data/spec/lib/caracal/core/lists_spec.rb +43 -0
  81. data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
  82. data/spec/lib/caracal/core/models/bookmark_model_spec.rb +135 -0
  83. data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
  84. data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
  85. data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
  86. data/spec/lib/caracal/core/models/image_model_spec.rb +225 -0
  87. data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
  88. data/spec/lib/caracal/core/models/link_model_spec.rb +179 -0
  89. data/spec/lib/caracal/core/models/list_item_model_spec.rb +197 -0
  90. data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
  91. data/spec/lib/caracal/core/models/list_style_model_spec.rb +198 -0
  92. data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
  93. data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
  94. data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
  95. data/spec/lib/caracal/core/models/page_number_model_spec.rb +136 -0
  96. data/spec/lib/caracal/core/models/page_size_model_spec.rb +101 -0
  97. data/spec/lib/caracal/core/models/paragraph_model_spec.rb +196 -0
  98. data/spec/lib/caracal/core/models/relationship_model_spec.rb +193 -0
  99. data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
  100. data/spec/lib/caracal/core/models/style_model_spec.rb +225 -0
  101. data/spec/lib/caracal/core/models/table_cell_model_spec.rb +230 -0
  102. data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
  103. data/spec/lib/caracal/core/models/text_model_spec.rb +154 -0
  104. data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
  105. data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
  106. data/spec/lib/caracal/core/page_numbers_spec.rb +89 -0
  107. data/spec/lib/caracal/core/page_settings_spec.rb +151 -0
  108. data/spec/lib/caracal/core/relationships_spec.rb +119 -0
  109. data/spec/lib/caracal/core/rules_spec.rb +25 -0
  110. data/spec/lib/caracal/core/styles_spec.rb +129 -0
  111. data/spec/lib/caracal/core/tables_spec.rb +25 -0
  112. data/spec/lib/caracal/core/text_spec.rb +52 -0
  113. data/spec/lib/caracal/errors_spec.rb +10 -0
  114. data/spec/spec_helper.rb +8 -0
  115. data/spec/support/_fixtures/snippet.docx +0 -0
  116. metadata +292 -0
@@ -0,0 +1,196 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::ParagraphModel do
4
+ subject do
5
+ described_class.new content: 'Lorem ipsum dolor....' do
6
+ style 'Fancy'
7
+ align :right
8
+ color '666666'
9
+ size 20
10
+ bold false
11
+ italic false
12
+ underline true
13
+ bgcolor 'cccccc'
14
+ end
15
+ end
16
+
17
+
18
+ #-------------------------------------------------------------
19
+ # Configuration
20
+ #-------------------------------------------------------------
21
+
22
+ describe 'configuration tests' do
23
+
24
+ # accessors
25
+ describe 'accessors' do
26
+ it { expect(subject.paragraph_style).to eq 'Fancy' }
27
+ it { expect(subject.paragraph_align).to eq :right }
28
+ it { expect(subject.paragraph_color).to eq '666666' }
29
+ it { expect(subject.paragraph_size).to eq 20 }
30
+ it { expect(subject.paragraph_bold).to eq false }
31
+ it { expect(subject.paragraph_italic).to eq false }
32
+ it { expect(subject.paragraph_underline).to eq true }
33
+ it { expect(subject.paragraph_bgcolor).to eq 'cccccc' }
34
+ end
35
+
36
+ end
37
+
38
+
39
+ #-------------------------------------------------------------
40
+ # Public Methods
41
+ #-------------------------------------------------------------
42
+
43
+ describe 'public method tests' do
44
+
45
+ #=============== GETTERS ==========================
46
+
47
+ # .runs
48
+ describe '.runs' do
49
+ it { expect(subject.runs).to be_a(Array) }
50
+ end
51
+
52
+ # .run_attributes
53
+ describe '.run_attributes' do
54
+ let(:expected) { { color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc' } }
55
+
56
+ it { expect(subject.run_attributes).to eq expected }
57
+ end
58
+
59
+
60
+ #=============== SETTERS ==========================
61
+
62
+ # booleans
63
+ describe '.bold' do
64
+ before { subject.bold(true) }
65
+
66
+ it { expect(subject.paragraph_bold).to eq true }
67
+ end
68
+ describe '.italic' do
69
+ before { subject.italic(true) }
70
+
71
+ it { expect(subject.paragraph_italic).to eq true }
72
+ end
73
+ describe '.underline' do
74
+ before { subject.underline(true) }
75
+
76
+ it { expect(subject.paragraph_underline).to eq true }
77
+ end
78
+
79
+ # integers
80
+ describe '.size' do
81
+ before { subject.size(24) }
82
+
83
+ it { expect(subject.paragraph_size).to eq 24 }
84
+ end
85
+
86
+ # strings
87
+ describe '.bgcolor' do
88
+ before { subject.bgcolor('dddddd') }
89
+
90
+ it { expect(subject.paragraph_bgcolor).to eq 'dddddd' }
91
+ end
92
+ describe '.color' do
93
+ before { subject.color('999999') }
94
+
95
+ it { expect(subject.paragraph_color).to eq '999999' }
96
+ end
97
+ describe '.style' do
98
+ before { subject.style('Dummy') }
99
+
100
+ it { expect(subject.paragraph_style).to eq 'Dummy' }
101
+ end
102
+
103
+ # symbols
104
+ describe '.align' do
105
+ before { subject.align(:center) }
106
+
107
+ it { expect(subject.paragraph_align).to eq :center }
108
+ end
109
+
110
+
111
+ #=============== SUB-METHODS ==========================
112
+
113
+ # .link
114
+ describe '.link' do
115
+ let!(:length) { subject.runs.length }
116
+
117
+ before { subject.link 'Text', 'http://www.google.com' }
118
+
119
+ it { expect(subject.runs.size).to eq length + 1 }
120
+ end
121
+
122
+ # .br
123
+ describe '.br' do
124
+ let!(:length) { subject.runs.length }
125
+
126
+ before { subject.br }
127
+
128
+ it { expect(subject.runs.size).to eq length + 1 }
129
+ end
130
+
131
+ # .text
132
+ describe '.text' do
133
+ let!(:length) { subject.runs.length }
134
+
135
+ before { subject.text 'Text' }
136
+
137
+ it { expect(subject.runs.size).to eq length + 1 }
138
+ end
139
+
140
+ # .bookmark
141
+ describe '.bookmark_start' do
142
+ let!(:length) { subject.runs.length }
143
+
144
+ before { subject.bookmark_start(id:'1', name:'abc')}
145
+
146
+ it { expect(subject.runs.size).to eq length + 1 }
147
+ end
148
+
149
+ describe '.bookmark_end' do
150
+ let!(:length) { subject.runs.length }
151
+
152
+ before { subject.bookmark_end {id:'1'}}
153
+
154
+ it { expect(subject.runs.size).to eq length + 1 }
155
+ end
156
+
157
+
158
+ #=============== VALIDATION ===========================
159
+
160
+ describe '.valid?' do
161
+ describe 'when at least one run exists' do
162
+ before do
163
+ allow(subject).to receive(:runs).and_return(['a'])
164
+ end
165
+
166
+ it { expect(subject.valid?).to eq true }
167
+ end
168
+ describe 'when no runs exist' do
169
+ before do
170
+ allow(subject).to receive(:runs).and_return([])
171
+ end
172
+
173
+ it { expect(subject.valid?).to eq false }
174
+ end
175
+ end
176
+
177
+ end
178
+
179
+
180
+ #-------------------------------------------------------------
181
+ # Private Methods
182
+ #-------------------------------------------------------------
183
+
184
+ describe 'private method tests' do
185
+
186
+ # .option_keys
187
+ describe '.option_keys' do
188
+ let(:actual) { subject.send(:option_keys).sort }
189
+ let(:expected) { [:content, :style, :align, :color, :size, :bold, :italic, :underline, :bgcolor].sort }
190
+
191
+ it { expect(actual).to eq expected }
192
+ end
193
+
194
+ end
195
+
196
+ end
@@ -0,0 +1,193 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::RelationshipModel do
4
+ subject do
5
+ described_class.new do
6
+ id 3
7
+ target 'footer.xml'
8
+ type :footer
9
+ end
10
+ end
11
+
12
+
13
+ #-------------------------------------------------------------
14
+ # Configuration
15
+ #-------------------------------------------------------------
16
+
17
+ describe 'configuration tests' do
18
+
19
+ # constants
20
+ describe 'constants' do
21
+ describe 'TYPE_MAP' do
22
+ let(:keys) { described_class::TYPE_MAP.keys }
23
+
24
+ it { expect(keys.include?(:font)).to be true }
25
+ end
26
+ end
27
+
28
+ # accessors
29
+ describe 'accessors' do
30
+ it { expect(subject.relationship_id).to eq 3 }
31
+ it { expect(subject.relationship_key).to eq 'footer.xml' }
32
+ it { expect(subject.relationship_type).to eq :footer }
33
+ it { expect(subject.relationship_target).to eq 'footer.xml' }
34
+ it { expect(subject.relationship_data).to eq nil }
35
+ end
36
+
37
+ end
38
+
39
+
40
+ #-------------------------------------------------------------
41
+ # Public Methods
42
+ #-------------------------------------------------------------
43
+
44
+ describe 'public method tests' do
45
+
46
+ #=================== ATTRIBUTES ==========================
47
+
48
+ # .id
49
+ describe '.id' do
50
+ before { subject.id(3) }
51
+
52
+ it { expect(subject.relationship_id).to eq 3 }
53
+ end
54
+
55
+ # .type
56
+ describe '.type' do
57
+ before do
58
+ subject.type('link')
59
+ end
60
+
61
+ it { expect(subject.relationship_type).to eq :link }
62
+ end
63
+
64
+ # .target
65
+ describe '.target' do
66
+ before do
67
+ subject.target('Dummy.XML')
68
+ end
69
+
70
+ it { expect(subject.relationship_target).to eq 'Dummy.XML' }
71
+ it { expect(subject.relationship_key).to eq 'dummy.xml' }
72
+ end
73
+
74
+ # .data
75
+ describe '.data' do
76
+ before do
77
+ subject.data('Dummy data')
78
+ end
79
+
80
+ it { expect(subject.relationship_data).to eq 'Dummy data' }
81
+ end
82
+
83
+
84
+ #=================== GETTERS =============================
85
+
86
+ # .formatted_id
87
+ describe '.formatted_id' do
88
+ before do
89
+ allow(subject).to receive(:relationship_id).and_return(1)
90
+ end
91
+
92
+ it { expect(subject.formatted_id).to eq 'rId1' }
93
+ end
94
+
95
+ # .formatted_target
96
+ describe '.formatted_target' do
97
+ describe 'when image' do
98
+ before do
99
+ allow(subject).to receive(:relationship_id).and_return(2)
100
+ allow(subject).to receive(:relationship_type).and_return(:image)
101
+ allow(subject).to receive(:relationship_target).and_return('https://www.google.com/images/srpr/logo11w.png')
102
+ end
103
+
104
+ it { expect(subject.formatted_target).to eq 'media/image2.png' }
105
+ end
106
+ describe 'when not image' do
107
+ before do
108
+ allow(subject).to receive(:relationship_type).and_return(:footer)
109
+ allow(subject).to receive(:relationship_target).and_return('footer.xml')
110
+ end
111
+
112
+ it { expect(subject.formatted_target).to eq 'footer.xml' }
113
+ end
114
+ end
115
+
116
+ # .formatted_type
117
+ describe '.formatted_type' do
118
+ it { expect(subject.formatted_type).to eq 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer' }
119
+ end
120
+
121
+
122
+ #=================== STATE ===============================
123
+
124
+ # .matches?
125
+ describe '.matches?' do
126
+ describe 'when search term matches key' do
127
+ let(:actual) { subject.matches?('footer.xml') }
128
+
129
+ it { expect(actual).to eq true }
130
+ end
131
+ describe 'when search term does not match key' do
132
+ let(:actual) { subject.matches?('dummy.xml') }
133
+
134
+ it { expect(actual).to eq false }
135
+ end
136
+ end
137
+
138
+ # .target_mode?
139
+ describe '.target_mode?' do
140
+ describe 'when key is link' do
141
+ before do
142
+ allow(subject).to receive(:relationship_type).and_return(:link)
143
+ end
144
+
145
+ it { expect(subject.target_mode?).to eq true }
146
+ end
147
+ describe 'when search term does not match key' do
148
+ before do
149
+ allow(subject).to receive(:relationship_type).and_return(:footer)
150
+ end
151
+
152
+ it { expect(subject.target_mode?).to eq false }
153
+ end
154
+ end
155
+
156
+
157
+ #=============== VALIDATION ===========================
158
+
159
+ describe '.valid?' do
160
+ describe 'when target and type provided' do
161
+ it { expect(subject.valid?).to eq true }
162
+ end
163
+ [:id, :target, :type].each do |prop|
164
+ describe "when #{ prop } nil" do
165
+ before do
166
+ allow(subject).to receive("relationship_#{ prop }").and_return(nil)
167
+ end
168
+
169
+ it { expect(subject.valid?).to eq false }
170
+ end
171
+ end
172
+ end
173
+
174
+ end
175
+
176
+
177
+ #-------------------------------------------------------------
178
+ # Private Methods
179
+ #-------------------------------------------------------------
180
+
181
+ describe 'private method tests' do
182
+
183
+ # .option_keys
184
+ describe '.option_keys' do
185
+ let(:actual) { subject.send(:option_keys).sort }
186
+ let(:expected) { [:id, :type, :target, :data].sort }
187
+
188
+ it { expect(actual).to eq expected }
189
+ end
190
+
191
+ end
192
+
193
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::RuleModel do
4
+ subject do
5
+ described_class.new do
6
+ color '666666'
7
+ size 8
8
+ spacing 2
9
+ line :double
10
+ end
11
+ end
12
+
13
+ #-------------------------------------------------------------
14
+ # Configuration
15
+ #-------------------------------------------------------------
16
+
17
+ describe 'configuration tests' do
18
+
19
+ # constants
20
+ describe 'inheritance' do
21
+ it { expect(subject).to be_a(Caracal::Core::Models::BorderModel) }
22
+ end
23
+
24
+ # accessors
25
+ describe 'accessors' do
26
+ it { expect(subject.rule_color).to eq '666666' }
27
+ it { expect(subject.rule_size).to eq 8 }
28
+ it { expect(subject.rule_spacing).to eq 2 }
29
+ it { expect(subject.rule_line).to eq :double }
30
+ end
31
+
32
+ end
33
+
34
+
35
+ #-------------------------------------------------------------
36
+ # Public Methods
37
+ #-------------------------------------------------------------
38
+
39
+ describe 'public method tests' do
40
+
41
+ #=============== SETTERS ==========================
42
+
43
+ # .color
44
+ describe '.color' do
45
+ before { subject.color('999999') }
46
+
47
+ it { expect(subject.rule_color).to eq '999999' }
48
+ end
49
+
50
+ # .line
51
+ describe '.line' do
52
+ before { subject.line(:single) }
53
+
54
+ it { expect(subject.rule_line).to eq :single }
55
+ end
56
+
57
+ # .size
58
+ describe '.size' do
59
+ before { subject.size(24) }
60
+
61
+ it { expect(subject.rule_size).to eq 24 }
62
+ end
63
+
64
+ # .spacing
65
+ describe '.spacing' do
66
+ before { subject.spacing(8) }
67
+
68
+ it { expect(subject.rule_spacing).to eq 8 }
69
+ end
70
+
71
+
72
+ #=============== VALIDATION ===========================
73
+
74
+ describe '.valid?' do
75
+ describe 'when all integers gt 0' do
76
+ it { expect(subject.valid?).to eq true }
77
+ end
78
+ [:size, :spacing].each do |d|
79
+ describe "when #{ d } lte 0" do
80
+ before do
81
+ allow(subject).to receive("border_#{ d }").and_return(0)
82
+ end
83
+
84
+ it { expect(subject.valid?).to eq false }
85
+ end
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+
92
+ #-------------------------------------------------------------
93
+ # Private Methods
94
+ #-------------------------------------------------------------
95
+
96
+ describe 'private method tests' do
97
+
98
+ # .option_keys
99
+ describe '.option_keys' do
100
+ let(:actual) { subject.send(:option_keys).sort }
101
+ let(:expected) { [:color, :size, :spacing, :line, :type].sort }
102
+
103
+ it { expect(actual).to eq expected }
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,225 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::StyleModel do
4
+ subject do
5
+ described_class.new do
6
+ id 'Normal'
7
+ name 'normal'
8
+ font 'Arial'
9
+ size 20
10
+ line 360
11
+ end
12
+ end
13
+
14
+ #-------------------------------------------------------------
15
+ # Configuration
16
+ #-------------------------------------------------------------
17
+
18
+ describe 'configuration tests' do
19
+
20
+ # constants
21
+ describe 'constants' do
22
+ it { expect(described_class::DEFAULT_STYLE_TYPE).to eq 'paragraph' }
23
+ it { expect(described_class::DEFAULT_STYLE_COLOR).to eq '333333' }
24
+ it { expect(described_class::DEFAULT_STYLE_SIZE).to eq 20 }
25
+ it { expect(described_class::DEFAULT_STYLE_BOLD).to eq false }
26
+ it { expect(described_class::DEFAULT_STYLE_ITALIC).to eq false }
27
+ it { expect(described_class::DEFAULT_STYLE_UNDERLINE).to eq false }
28
+ it { expect(described_class::DEFAULT_STYLE_CAPS).to eq false }
29
+ it { expect(described_class::DEFAULT_STYLE_ALIGN).to eq :left }
30
+ it { expect(described_class::DEFAULT_STYLE_TOP).to eq 0 }
31
+ it { expect(described_class::DEFAULT_STYLE_BOTTOM).to eq 0 }
32
+ it { expect(described_class::DEFAULT_STYLE_LINE).to eq 360 }
33
+ it { expect(described_class::DEFAULT_STYLE_BASE).to eq 'Normal' }
34
+ it { expect(described_class::DEFAULT_STYLE_NEXT).to eq 'Normal' }
35
+ end
36
+
37
+ # accessors
38
+ describe 'accessors' do
39
+ it { expect(subject.style_default).to eq true }
40
+ it { expect(subject.style_id).to eq 'Normal' }
41
+ it { expect(subject.style_name).to eq 'normal' }
42
+ it { expect(subject.style_type).to eq 'paragraph' }
43
+ it { expect(subject.style_color).to eq '333333' }
44
+ it { expect(subject.style_font).to eq 'Arial' }
45
+ it { expect(subject.style_size).to eq 20 }
46
+ it { expect(subject.style_bold).to eq false }
47
+ it { expect(subject.style_italic).to eq false }
48
+ it { expect(subject.style_underline).to eq false }
49
+ it { expect(subject.style_caps).to eq false }
50
+ it { expect(subject.style_align).to eq :left }
51
+ it { expect(subject.style_top).to eq 0 }
52
+ it { expect(subject.style_bottom).to eq 0 }
53
+ it { expect(subject.style_line).to eq 360 }
54
+ it { expect(subject.style_base).to eq 'Normal' }
55
+ it { expect(subject.style_next).to eq 'Normal' }
56
+ end
57
+
58
+ end
59
+
60
+
61
+ #-------------------------------------------------------------
62
+ # Public Methods
63
+ #-------------------------------------------------------------
64
+
65
+ describe 'public method tests' do
66
+
67
+ #=============== SETTERS ==========================
68
+
69
+ # booleans
70
+ describe '.bold' do
71
+ before { subject.bold(true) }
72
+
73
+ it { expect(subject.style_bold).to eq true }
74
+ end
75
+ describe '.italic' do
76
+ before { subject.italic(true) }
77
+
78
+ it { expect(subject.style_italic).to eq true }
79
+ end
80
+ describe '.underline' do
81
+ before { subject.underline(true) }
82
+
83
+ it { expect(subject.style_underline).to eq true }
84
+ end
85
+ describe '.caps' do
86
+ before { subject.caps(true) }
87
+
88
+ it { expect(subject.style_caps).to eq true }
89
+ end
90
+
91
+ # integers
92
+ describe '.bottom' do
93
+ before { subject.bottom(100) }
94
+
95
+ it { expect(subject.style_bottom).to eq 100 }
96
+ end
97
+ describe '.size' do
98
+ before { subject.size(24) }
99
+
100
+ it { expect(subject.style_size).to eq 24 }
101
+ end
102
+ describe '.line' do
103
+ before { subject.line(480) }
104
+
105
+ it { expect(subject.style_line).to eq 480 }
106
+ end
107
+ describe '.top' do
108
+ before { subject.top(100) }
109
+
110
+ it { expect(subject.style_top).to eq 100 }
111
+ end
112
+ describe '.indent_left' do
113
+ before { subject.indent_left(1440) }
114
+
115
+ it { expect(subject.style_indent_left).to eq 1440 }
116
+ end
117
+ describe '.indent_right' do
118
+ before { subject.indent_right(720) }
119
+
120
+ it { expect(subject.style_indent_right).to eq 720 }
121
+ end
122
+ describe '.indent_right' do
123
+ before { subject.indent_first(567) }
124
+
125
+ it { expect(subject.style_indent_first).to eq 567 }
126
+ end
127
+
128
+ # strings
129
+ describe '.id' do
130
+ before { subject.id('heading1') }
131
+
132
+ it { expect(subject.style_id).to eq 'heading1' }
133
+ end
134
+ describe '.name' do
135
+ before { subject.name('Heading 1') }
136
+
137
+ it { expect(subject.style_name).to eq 'Heading 1' }
138
+ end
139
+ describe '.color' do
140
+ before { subject.color('444444') }
141
+
142
+ it { expect(subject.style_color).to eq '444444' }
143
+ end
144
+ describe '.font' do
145
+ before { subject.font('Helvetica') }
146
+
147
+ it { expect(subject.style_font).to eq 'Helvetica' }
148
+ end
149
+
150
+ # symbols
151
+ describe '.align' do
152
+ before { subject.align(:right) }
153
+
154
+ it { expect(subject.style_align).to eq :right }
155
+ end
156
+
157
+ # custom
158
+ describe '.type' do
159
+ describe 'when valid' do
160
+ before { subject.type 'character'}
161
+
162
+ it { expect(subject.style_type).to eq 'character' }
163
+ end
164
+ describe 'when invalid' do
165
+ before { subject.type 'bogus'}
166
+
167
+ it { expect(subject.style_type).to eq 'paragraph' }
168
+ end
169
+ end
170
+
171
+
172
+ #=================== STATE ===============================
173
+
174
+ # .matches?
175
+ describe '.matches?' do
176
+ describe 'when search term matches' do
177
+ let(:actual) { subject.matches?('normal') }
178
+
179
+ it { expect(actual).to eq true }
180
+ end
181
+ describe 'when search term does not match' do
182
+ let(:actual) { subject.matches?('Dummy') }
183
+
184
+ it { expect(actual).to eq false }
185
+ end
186
+ end
187
+
188
+
189
+ #=============== VALIDATION ===========================
190
+
191
+ describe '.valid?' do
192
+ describe 'when type and id provided' do
193
+ it { expect(subject.valid?).to eq true }
194
+ end
195
+ [:id, :name].each do |prop|
196
+ describe "when #{ prop } nil" do
197
+ before do
198
+ allow(subject).to receive("style_#{ prop }").and_return(nil)
199
+ end
200
+
201
+ it { expect(subject.valid?).to eq false }
202
+ end
203
+ end
204
+ end
205
+
206
+ end
207
+
208
+
209
+ #-------------------------------------------------------------
210
+ # Private Methods
211
+ #-------------------------------------------------------------
212
+
213
+ describe 'private method tests' do
214
+
215
+ # .option_keys
216
+ describe '.option_keys' do
217
+ let(:actual) { subject.send(:option_keys).sort }
218
+ let(:expected) { [:type, :bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align, :indent_left, :indent_right, :indent_first].sort }
219
+
220
+ it { expect(actual).to eq expected }
221
+ end
222
+
223
+ end
224
+
225
+ end