libis-tools 1.0.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +16 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +40 -0
  6. data/Gemfile +7 -0
  7. data/README.md +202 -0
  8. data/Rakefile +11 -0
  9. data/bin/libis_tool +5 -0
  10. data/lib/libis-tools.rb +1 -0
  11. data/lib/libis/tools.rb +25 -0
  12. data/lib/libis/tools/assert.rb +52 -0
  13. data/lib/libis/tools/checksum.rb +106 -0
  14. data/lib/libis/tools/cli/cli_helper.rb +189 -0
  15. data/lib/libis/tools/cli/reorg.rb +416 -0
  16. data/lib/libis/tools/command.rb +133 -0
  17. data/lib/libis/tools/command_line.rb +23 -0
  18. data/lib/libis/tools/config.rb +147 -0
  19. data/lib/libis/tools/config_file.rb +85 -0
  20. data/lib/libis/tools/csv.rb +38 -0
  21. data/lib/libis/tools/deep_struct.rb +71 -0
  22. data/lib/libis/tools/extend/array.rb +16 -0
  23. data/lib/libis/tools/extend/empty.rb +7 -0
  24. data/lib/libis/tools/extend/hash.rb +147 -0
  25. data/lib/libis/tools/extend/kernel.rb +25 -0
  26. data/lib/libis/tools/extend/ostruct.rb +3 -0
  27. data/lib/libis/tools/extend/roo.rb +91 -0
  28. data/lib/libis/tools/extend/string.rb +94 -0
  29. data/lib/libis/tools/extend/struct.rb +29 -0
  30. data/lib/libis/tools/extend/symbol.rb +8 -0
  31. data/lib/libis/tools/logger.rb +130 -0
  32. data/lib/libis/tools/mets_dnx.rb +61 -0
  33. data/lib/libis/tools/mets_file.rb +504 -0
  34. data/lib/libis/tools/mets_objects.rb +547 -0
  35. data/lib/libis/tools/parameter.rb +372 -0
  36. data/lib/libis/tools/spreadsheet.rb +196 -0
  37. data/lib/libis/tools/temp_file.rb +42 -0
  38. data/lib/libis/tools/thread_safe.rb +31 -0
  39. data/lib/libis/tools/version.rb +5 -0
  40. data/lib/libis/tools/xml_document.rb +583 -0
  41. data/libis-tools.gemspec +55 -0
  42. data/spec/assert_spec.rb +65 -0
  43. data/spec/checksum_spec.rb +68 -0
  44. data/spec/command_spec.rb +90 -0
  45. data/spec/config_file_spec.rb +83 -0
  46. data/spec/config_spec.rb +113 -0
  47. data/spec/csv_spec.rb +159 -0
  48. data/spec/data/test-headers.csv +2 -0
  49. data/spec/data/test-headers.tsv +2 -0
  50. data/spec/data/test-noheaders.csv +1 -0
  51. data/spec/data/test-noheaders.tsv +1 -0
  52. data/spec/data/test.data +9 -0
  53. data/spec/data/test.xlsx +0 -0
  54. data/spec/data/test.xml +8 -0
  55. data/spec/data/test.yml +2 -0
  56. data/spec/data/test_config.yml +15 -0
  57. data/spec/deep_struct_spec.rb +138 -0
  58. data/spec/logger_spec.rb +165 -0
  59. data/spec/mets_file_spec.rb +223 -0
  60. data/spec/parameter_container_spec.rb +152 -0
  61. data/spec/parameter_spec.rb +148 -0
  62. data/spec/spec_helper.rb +29 -0
  63. data/spec/spreadsheet_spec.rb +1820 -0
  64. data/spec/temp_file_spec.rb +76 -0
  65. data/spec/test.xsd +20 -0
  66. data/spec/thread_safe_spec.rb +64 -0
  67. data/spec/xmldocument_spec.rb +421 -0
  68. data/test/test_helper.rb +7 -0
  69. data/test/webservices/test_ca_item_info.rb +59 -0
  70. data/test/webservices/test_ca_search.rb +35 -0
  71. metadata +437 -0
@@ -0,0 +1,223 @@
1
+ # encoding: utf-8
2
+ require_relative 'spec_helper'
3
+ require 'rspec/matchers'
4
+ require 'equivalent-xml'
5
+ require 'libis/tools/mets_file'
6
+ require 'libis/tools/xml_document'
7
+
8
+ describe 'METS File' do
9
+
10
+ before(:all) do
11
+ ::Libis::Tools::Config << {appname: 'LIBIS Default'}
12
+ end
13
+
14
+ subject(:mets_file) { ::Libis::Tools::MetsFile.new }
15
+
16
+ context 'without data' do
17
+
18
+ let(:skeleton) {
19
+ ::Libis::Tools::XmlDocument.build do |xml|
20
+ # noinspection RubyResolve
21
+ xml[:mets].mets 'xmlns:mets' => 'http://www.loc.gov/METS/' do
22
+ xml[:mets].amdSec 'ID' => 'ie-amd'
23
+ xml[:mets].fileSec
24
+ end
25
+ end.document
26
+ }
27
+
28
+ it 'generates skeleton XML' do
29
+ expect(mets_file.xml_doc.root).to be_equivalent_to skeleton.root
30
+ end
31
+
32
+ end
33
+
34
+ context 'with IE AMD' do
35
+
36
+ let(:dc_record) {
37
+ Libis::Tools::XmlDocument.parse <<-STR
38
+ <?xml version="1.0" encoding="UTF-8"?>
39
+ <record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
40
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
41
+ xmlns:dcterms="http://purl.org/dc/terms/">
42
+ <dc:title>Title</dc:title>
43
+ <dc:author>Author</dc:author>
44
+ <dc:subject>Subject</dc:subject>
45
+ </record>
46
+ STR
47
+ }
48
+
49
+ let(:marc_record) {
50
+ Libis::Tools::XmlDocument.parse <<-STR
51
+ <?xml version="1.0" encoding="UTF-8"?>
52
+ <record xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
53
+ xmlns="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
54
+ <leader>abcdefghiljklmnopqrstuvwxyz</leader>
55
+ <controlfield tag="001">1234567890</controlfield>
56
+ <datafield tag="010" ind1="a" ind2="b">
57
+ <subfield code="a">abc</subfield>
58
+ <subfield code="b">xyz</subfield>
59
+ </datafield>
60
+ </record>
61
+ STR
62
+ }
63
+
64
+ let(:src_record) {
65
+ Libis::Tools::XmlDocument.parse <<-STR
66
+ <my_description xmlns="http://www.libis.be/description/">
67
+ <title>Title</title>
68
+ <importance>high</importance>
69
+ <location>here</location>
70
+ </my_description>
71
+ STR
72
+ }
73
+
74
+ let(:target) {
75
+ # noinspection RubyResolve
76
+ ::Libis::Tools::XmlDocument.build do |xml|
77
+ # noinspection RubyResolve
78
+ xml[:mets].mets 'xmlns:mets' => 'http://www.loc.gov/METS/' do
79
+ # noinspection RubyResolve
80
+ xml[:mets].amdSec ID: 'ie-amd' do
81
+ # noinspection RubyResolve
82
+ xml[:mets].techMD ID: 'ie-amd-tech' do
83
+ # noinspection RubyResolve
84
+ xml[:mets].mdWrap MDTYPE: 'OTHER', OTHERMDTYPE: 'dnx' do
85
+ # noinspection RubyResolve
86
+ xml[:mets].xmlData do
87
+ xml.dnx xmlns: 'http://www.exlibrisgroup.com/dps/dnx' do
88
+ # noinspection RubyResolve
89
+ xml.section.objectCharacteristics! do
90
+ xml.record do
91
+ # noinspection RubyResolve
92
+ xml.key.groupID! 'group_id'
93
+ end
94
+ end
95
+ # noinspection RubyResolve
96
+ xml.section.generalIECharacteristics! do
97
+ # noinspection RubyResolve
98
+ xml.record do
99
+ xml.key.status! 'status'
100
+ xml.key.IEEntityType! 'entity_type'
101
+ xml.key.UserDefinedA! 'user_a'
102
+ xml.key.UserDefinedB! 'user_b'
103
+ xml.key.UserDefinedC! 'user_c'
104
+ xml.key.submissionReason! 'submission_reason'
105
+ end
106
+ end
107
+ # noinspection RubyResolve
108
+ xml.section.retentionPolicy! do
109
+ # noinspection RubyResolve
110
+ xml.record do
111
+ xml.key.policyId! 'retention_id'
112
+ end
113
+ end
114
+ # noinspection RubyResolve
115
+ xml.section.webHarvesting! do
116
+ # noinspection RubyResolve
117
+ xml.record do
118
+ xml.key.primarySeedURL! 'harvest_url'
119
+ xml.key.WCTIdentifier! 'harvest_id'
120
+ xml.key.targetName! 'harvest_target'
121
+ xml.key.group! 'harvest_group'
122
+ xml.key.harvestDate! 'harvest_date'
123
+ xml.key.harvestTime! 'harvest_time'
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ # noinspection RubyResolve
131
+ xml[:mets].rightsMD ID: 'ie-amd-rights' do
132
+ # noinspection RubyResolve
133
+ xml[:mets].mdWrap MDTYPE: 'OTHER', OTHERMDTYPE: 'dnx' do
134
+ # noinspection RubyResolve
135
+ xml[:mets].xmlData do
136
+ xml.dnx xmlns: 'http://www.exlibrisgroup.com/dps/dnx' do
137
+ # noinspection RubyResolve
138
+ xml.section.accessRightsPolicy! do
139
+ # noinspection RubyResolve
140
+ xml.record do
141
+ xml.key.policyId! 'access_right'
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ # noinspection RubyResolve
149
+ xml[:mets].sourceMD ID: 'ie-amd-source-DC-1' do
150
+ # noinspection RubyResolve
151
+ xml[:mets].mdWrap MDTYPE: 'DC' do
152
+ # noinspection RubyResolve
153
+ xml[:mets].xmlData do
154
+ # xml.parent.namespace = xml.parent.namespace_definitions.first
155
+ xml.parent << dc_record.root.to_xml
156
+ end
157
+ end
158
+ end
159
+ # noinspection RubyResolve
160
+ xml[:mets].sourceMD ID: 'ie-amd-source-MARC-2' do
161
+ # noinspection RubyResolve
162
+ xml[:mets].mdWrap MDTYPE: 'MARC' do
163
+ # noinspection RubyResolve
164
+ xml[:mets].xmlData do
165
+ # xml.parent.namespace = xml.parent.namespace_definitions.first
166
+ xml.parent << marc_record.root.to_xml
167
+ end
168
+ end
169
+ end
170
+ # noinspection RubyResolve
171
+ xml[:mets].sourceMD ID: 'ie-amd-source-OTHER-3' do
172
+ # noinspection RubyResolve
173
+ xml[:mets].mdWrap MDTYPE: 'OTHER' do
174
+ # noinspection RubyResolve
175
+ xml[:mets].xmlData do
176
+ # xml.namespace = xml.parent.namespace_definitions.first
177
+ xml.parent << src_record.root.to_xml
178
+ end
179
+ end
180
+ end
181
+ end
182
+ xml[:mets].fileSec
183
+ end
184
+ end.document
185
+ }
186
+
187
+ it 'fills in IE-AMD section' do
188
+ mets_file.amd_info = {
189
+ group_id: 'group_id',
190
+ status: 'status',
191
+ entity_type: 'entity_type',
192
+ user_a: 'user_a',
193
+ user_b: 'user_b',
194
+ user_c: 'user_c',
195
+ submission_reason: 'submission_reason',
196
+ retention_id: 'retention_id',
197
+ harvest_url: 'harvest_url',
198
+ harvest_id: 'harvest_id',
199
+ harvest_target: 'harvest_target',
200
+ harvest_group: 'harvest_group',
201
+ harvest_date: 'harvest_date',
202
+ harvest_time: 'harvest_time',
203
+ access_right: 'access_right',
204
+ source_metadata: [
205
+ {
206
+ type: 'DC',
207
+ data: dc_record.root.to_xml
208
+ }, {
209
+ type: 'Marc',
210
+ data: marc_record.root.to_xml
211
+ }, {
212
+ type: 'other',
213
+ data: src_record.root.to_xml
214
+ }
215
+ ]
216
+ }
217
+
218
+ expect(mets_file.xml_doc.root).to be_equivalent_to target.root
219
+
220
+ end
221
+ end
222
+
223
+ end
@@ -0,0 +1,152 @@
1
+ # encoding: utf-8
2
+ require_relative 'spec_helper'
3
+ require 'libis/tools/parameter'
4
+
5
+ describe 'ParameterContainer' do
6
+
7
+ class TestContainer
8
+ include ::Libis::Tools::ParameterContainer
9
+
10
+ parameter check: true, description: 'check parameter'
11
+ parameter count: 0, description: 'count parameter'
12
+ parameter price: 1.0, description: 'price parameter'
13
+ parameter name: 'nobody', description: 'name parameter'
14
+ parameter calendar: Date.new(2014, 01, 01)
15
+ parameter clock: Time.parse('10:10')
16
+ parameter timestamp: DateTime.new(2014, 01, 01, 10, 10)
17
+ parameter with_options: true, options: {a: 1, b: 2}, c: 3
18
+
19
+ end
20
+
21
+ class DerivedContainer < TestContainer
22
+ parameter name: 'somebody', description: 'derived name parameter', frozen: true
23
+ parameter check: 'no'
24
+ parameter new_derived_param: false
25
+ end
26
+
27
+ class DerivedDerivedContainer < DerivedContainer
28
+ parameter price: 2.0, description: 'derived derived price parameter'
29
+ end
30
+
31
+ class DerivedDerivedDerivedContainer < DerivedDerivedContainer
32
+ parameter price: 3.0, description: 'derived derived derived price parameter'
33
+ end
34
+
35
+ let(:test_container) { TestContainer.new }
36
+ let(:derived_container) { DerivedContainer.new }
37
+ let(:derived_derived_container) { DerivedDerivedContainer.new }
38
+ let(:derived_derived_derived_container) { DerivedDerivedDerivedContainer.new }
39
+
40
+ it 'class should return parameter if only name is given' do
41
+ [:check, :count, :price, :name, :calendar, :clock, :timestamp].each do |v|
42
+ expect(TestContainer.parameter(v)).to be_a ::Libis::Tools::Parameter
43
+ end
44
+ end
45
+
46
+ it 'should have default parameters' do
47
+ expect(test_container.parameter(:check)).to be_truthy
48
+ expect(test_container.parameter(:count)).to eq 0
49
+ expect(test_container.parameter(:price)).to eq 1.0
50
+ expect(test_container.parameter(:name)).to eq 'nobody'
51
+ expect(test_container.parameter(:calendar).year).to eq 2014
52
+ expect(test_container.parameter(:calendar).month).to eq 1
53
+ expect(test_container.parameter(:calendar).day).to eq 1
54
+ expect(test_container.parameter(:clock).hour).to eq 10
55
+ expect(test_container.parameter(:clock).min).to eq 10
56
+ expect(test_container.parameter(:clock).sec).to eq 0
57
+ expect(test_container.parameter(:timestamp).year).to eq 2014
58
+ expect(test_container.parameter(:timestamp).month).to eq 1
59
+ expect(test_container.parameter(:timestamp).day).to eq 1
60
+ expect(test_container.parameter(:timestamp).hour).to eq 10
61
+ expect(test_container.parameter(:timestamp).min).to eq 10
62
+ expect(test_container.parameter(:timestamp).sec).to eq 0
63
+ end
64
+
65
+ it 'should allow to set values' do
66
+ test_container.parameter(:check, false)
67
+ expect(test_container.parameter(:check)).to be_falsey
68
+
69
+ test_container.parameter(:count, 99)
70
+ expect(test_container.parameter(:count)).to eq 99
71
+
72
+ test_container.parameter(:price, 99.99)
73
+ expect(test_container.parameter(:price)).to eq 99.99
74
+
75
+ test_container.parameter(:name, 'everybody')
76
+ expect(test_container.parameter(:name)).to eq 'everybody'
77
+
78
+ test_container.parameter(:calendar, Date.new(2015, 02, 03))
79
+ expect(test_container.parameter(:calendar).year).to eq 2015
80
+ expect(test_container.parameter(:calendar).month).to eq 2
81
+ expect(test_container.parameter(:calendar).day).to eq 3
82
+
83
+ test_container.parameter(:clock, Time.parse('14:40:23'))
84
+ expect(test_container.parameter(:clock).hour).to eq 14
85
+ expect(test_container.parameter(:clock).min).to eq 40
86
+ expect(test_container.parameter(:clock).sec).to eq 23
87
+
88
+ test_container.parameter(:timestamp, DateTime.new(2015, 02, 03, 14, 40, 23))
89
+ expect(test_container.parameter(:timestamp).year).to eq 2015
90
+ expect(test_container.parameter(:timestamp).month).to eq 2
91
+ expect(test_container.parameter(:timestamp).day).to eq 3
92
+ expect(test_container.parameter(:timestamp).hour).to eq 14
93
+ expect(test_container.parameter(:timestamp).min).to eq 40
94
+ expect(test_container.parameter(:timestamp).sec).to eq 23
95
+ end
96
+
97
+ it 'should be able to define parameter with options' do
98
+ expect(test_container.class.parameter(:with_options)[:options]).to eq a: 1, b: 2, c: 3
99
+ expect(test_container.class.parameter(:with_options)[:options][:a]).to be 1
100
+ expect(test_container.class.parameter(:with_options)[:a]).to be 1
101
+ expect(test_container.class.parameter(:with_options)[:options][:c]).to be 3
102
+ expect(test_container.class.parameter(:with_options)[:c]).to be 3
103
+ end
104
+
105
+ it 'derived class should inherit parameters of the parent class' do
106
+ expect(derived_container.parameter(:price)).to eq 1.0
107
+ expect(derived_container.class.parameter(:price)[:description]).to eq 'price parameter'
108
+ end
109
+
110
+ it 'derived class should override parameter values and propertiesfrom parent class' do
111
+ expect(derived_container.parameter(:name)).to eq 'somebody'
112
+ expect(derived_container.parameter(:check)).to eq 'no'
113
+ end
114
+
115
+ it 'overrides in the derived classes should not change values in the parent classes' do
116
+ expect(test_container.parameter(:check)).to eq true
117
+ expect(test_container.parameter(:price)).to eq 1.0
118
+ expect(test_container.class.parameter(:price)[:description]).to eq 'price parameter'
119
+ end
120
+
121
+ it 'derivation should be supported over multiple levels' do
122
+ expect(derived_container.parameter(:price)).to eq 1.0
123
+ expect(derived_derived_container.parameter(:price)).to eq 2.0
124
+ expect(derived_derived_derived_container.parameter(:price)).to eq 3.0
125
+ expect(derived_container.class.parameter(:price)[:description]).to eq 'price parameter'
126
+ expect(derived_derived_container.class.parameter(:price)[:description]).to eq 'derived derived price parameter'
127
+ expect(derived_derived_derived_container.class.parameter(:price)[:description]).to eq 'derived derived derived price parameter'
128
+ end
129
+
130
+ it 'frozen parameters should be read-only' do
131
+ expect {
132
+ derived_container.parameter(:name, 'anybody')
133
+ }.to raise_error(::Libis::Tools::ParameterFrozenError)
134
+ expect(derived_container.parameter(:name)).to eq 'somebody'
135
+ expect {
136
+ derived_container[:name] = 'anybody'
137
+ }.not_to raise_error
138
+ expect(derived_container[:name]).to eq 'somebody'
139
+ end
140
+
141
+ it 'frozen state should not affect parameter in parent class' do
142
+ expect {
143
+ test_container.parameter(:name, 'anybody')
144
+ }.not_to raise_error
145
+ expect(test_container.parameter(:name)).to eq 'anybody'
146
+ expect {
147
+ test_container[:name] = 'everybody'
148
+ }.not_to raise_error
149
+ expect(test_container[:name]).to eq 'everybody'
150
+ end
151
+
152
+ end
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+ require_relative 'spec_helper'
3
+ require 'libis/tools/parameter'
4
+
5
+ describe 'Parameter' do
6
+
7
+ before :context do
8
+ @parameter_types = %w'bool string int float datetime'
9
+
10
+ @bool_parameter = ::Libis::Tools::Parameter.new('BoolParam', true)
11
+ @string_parameter = ::Libis::Tools::Parameter.new('StringParam', 'default string')
12
+ @int_parameter = ::Libis::Tools::Parameter.new('IntParam', 5)
13
+ @float_parameter = ::Libis::Tools::Parameter.new('FloatParam', 1.0)
14
+ @datetime_parameter = ::Libis::Tools::Parameter.new('DateTimeParam', DateTime.now)
15
+
16
+ @constrained_bool_parameter = ::Libis::Tools::Parameter.new('BoolParam', true, nil, nil, true)
17
+ @constrained_string_parameter = ::Libis::Tools::Parameter.new('StringParam', 'default string', nil, nil, /^ABC.*XYZ$/i)
18
+ @constrained_int_parameter = ::Libis::Tools::Parameter.new('IntParam', 5, nil, nil, [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37])
19
+ @constrained_float_parameter = ::Libis::Tools::Parameter.new('FloatParam', 0.0, nil, nil, 1.0...3.1415927)
20
+ end
21
+
22
+ it 'should detect datatype from default value' do
23
+ @parameter_types.each do |dtype|
24
+ expect(eval("@#{dtype}_parameter").send(:guess_datatype)).to eq dtype
25
+ end
26
+ end
27
+
28
+ it 'should return default value' do
29
+ @parameter_types.each do |dtype|
30
+ expect(eval("@#{dtype}_parameter").parse).to eq eval("@#{dtype}_parameter").default
31
+ end
32
+ end
33
+
34
+ it 'should test if boolean value is valid' do
35
+ [false, true, nil, 'true', 'false', 'T', 'F', 'y', 'n', 1, 0].each do |v|
36
+ # noinspection RubyResolve
37
+ expect(@bool_parameter).to be_valid_value(v)
38
+ end
39
+
40
+ [5, 0.1, 'abc'].each do |v|
41
+ # noinspection RubyResolve
42
+ expect(@bool_parameter).not_to be_valid_value(v)
43
+ end
44
+ end
45
+
46
+ it 'should test if string value is valid' do
47
+ ['abc', true, false, nil, 1, 1.0, Object.new].each do |v|
48
+ # noinspection RubyResolve
49
+ expect(@string_parameter).to be_valid_value(v)
50
+ end
51
+ end
52
+
53
+ it 'should test if integer value is valid' do
54
+ [0, 5, -6, 3.1415926, '3', nil, Rational('1/3')].each do |v|
55
+ # noinspection RubyResolve
56
+ expect(@int_parameter).to be_valid_value(v)
57
+ end
58
+
59
+ ['abc', '3.1415926', '1 meter', false, true, Object.new].each do |v|
60
+ # noinspection RubyResolve
61
+ expect(@int_parameter).not_to be_valid_value(v)
62
+ end
63
+ end
64
+
65
+ it 'should test if float value is valid' do
66
+ [1.1, Rational('1/3'), 3.1415926, '3.1415926', nil].each do |v|
67
+ # noinspection RubyResolve
68
+ expect(@float_parameter).to be_valid_value(v)
69
+ end
70
+
71
+ ['abc', '1.0.0', false, true, Object.new].each do |v|
72
+ # noinspection RubyResolve
73
+ expect(@float_parameter).not_to be_valid_value(v)
74
+ end
75
+ end
76
+
77
+ it 'should test if datetime value is valid' do
78
+ [Time.now, Date.new, '10:10', '2014/01/01', '2014/01/01 10:10:10.000001', nil].each do |v|
79
+ # noinspection RubyResolve
80
+ expect(@datetime_parameter).to be_valid_value(v)
81
+ end
82
+
83
+ ['abc', 5, false].each do |v|
84
+ # noinspection RubyResolve
85
+ expect(@datetime_parameter).not_to be_valid_value(v)
86
+ end
87
+ end
88
+
89
+ it 'should accept and convert value for boolean parameter' do
90
+ ['true', 'True', 'TRUE','tRuE', 't', 'T', 'y', 'Y', '1', 1].each do |v|
91
+ expect(@bool_parameter.parse(v)).to be_truthy
92
+ end
93
+
94
+ ['false', 'False', 'FALSE','fAlSe', 'f', 'F', 'n', 'N', '0', 0].each do |v|
95
+ expect(@bool_parameter.parse(v)).to be_falsey
96
+ end
97
+ end
98
+
99
+ # noinspection RubyResolve
100
+ it 'should check values against constraint' do
101
+ expect(@constrained_bool_parameter).to be_valid_value(true)
102
+ expect(@constrained_bool_parameter).to be_valid_value('y')
103
+
104
+ expect(@constrained_bool_parameter).not_to be_valid_value(false)
105
+ expect(@constrained_bool_parameter).not_to be_valid_value('n')
106
+
107
+ %w'ABCXYZ ABC123XYZ abcxyz AbC__++__xYz'.each do |v|
108
+ # noinspection RubyResolve
109
+ expect(@constrained_string_parameter).to be_valid_value(v)
110
+ end
111
+
112
+ %w'ABC XYZ ABC123'.each do |v|
113
+ # noinspection RubyResolve
114
+ expect(@constrained_string_parameter).not_to be_valid_value(v)
115
+ end
116
+
117
+ [1, 7, 11, nil].each do |v|
118
+ # noinspection RubyResolve
119
+ expect(@constrained_int_parameter).to be_valid_value(v)
120
+ end
121
+
122
+ [0, 4, 9, 43].each do |v|
123
+ # noinspection RubyResolve
124
+ expect(@constrained_int_parameter).not_to be_valid_value(v)
125
+ end
126
+
127
+ [1.0, 3.1415, 2.718281828459].each do |v|
128
+ # noinspection RubyResolve
129
+ expect(@constrained_float_parameter).to be_valid_value(v)
130
+ end
131
+
132
+ [nil, 0.5, -2.5].each do |v|
133
+ # noinspection RubyResolve
134
+ expect(@constrained_float_parameter).not_to be_valid_value(v)
135
+ end
136
+
137
+ end
138
+
139
+ it 'should allow to set and get options' do
140
+
141
+ @bool_parameter[:my_value] = :dummy_value
142
+
143
+ expect(@bool_parameter[:my_value]).to be :dummy_value
144
+ expect(@bool_parameter[:options][:my_value]).to be :dummy_value
145
+
146
+ end
147
+
148
+ end