rpi_marca 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26fc80df7a7e54eb33df1bbdc9567611a5f738eb
4
+ data.tar.gz: ddbb56e2a55a1c4455bb710599dd62647dcc3851
5
+ SHA512:
6
+ metadata.gz: 015f9db40e214356909c4ceec4dc914a241836e778985e43073a32e5543875656077a6b652b302f50299cacf02184059b6799b904124732d9abb7467bf81348f
7
+ data.tar.gz: b7048d383d51e848de7fbd907b61f93d01bbb960ccd42288f0e9792e26891147d9780dace932be798035aa40f59380ae2c02044a5c22f21dc5b0152045dbe8fb
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+
15
+ *.sublime-workspace
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # Métodos inicializadores. Mantidos para saber quais os argumentos
4
+ # possíveis.
5
+ Metrics/ParameterLists:
6
+ Exclude:
7
+ - '**/vienna_class.rb'
8
+ - '**/receipt.rb'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,16 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-12-03 14:20:23 -0200 using RuboCop version 0.27.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 5
9
+ # Cop supports --auto-correct.
10
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
11
+ Style/AndOr:
12
+ Enabled: false
13
+
14
+ # Offense count: 13
15
+ Style/Documentation:
16
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rpi_marca.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rpi_marca (0.0.1)
5
+ nokogiri (~> 1.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ celluloid (0.16.0)
11
+ timers (~> 4.0.0)
12
+ coderay (1.1.0)
13
+ diff-lcs (1.2.5)
14
+ docile (1.1.5)
15
+ ffi (1.9.6)
16
+ formatador (0.2.5)
17
+ guard (2.8.0)
18
+ formatador (>= 0.2.4)
19
+ listen (~> 2.7)
20
+ lumberjack (~> 1.0)
21
+ pry (>= 0.9.12)
22
+ thor (>= 0.18.1)
23
+ guard-rspec (4.3.1)
24
+ guard (~> 2.1)
25
+ rspec (>= 2.14, < 4.0)
26
+ hitimes (1.2.2)
27
+ listen (2.7.11)
28
+ celluloid (>= 0.15.2)
29
+ rb-fsevent (>= 0.9.3)
30
+ rb-inotify (>= 0.9)
31
+ lumberjack (1.0.9)
32
+ method_source (0.8.2)
33
+ mini_portile (0.6.1)
34
+ multi_json (1.10.1)
35
+ nokogiri (1.6.4)
36
+ mini_portile (~> 0.6.0)
37
+ pry (0.10.1)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.8.1)
40
+ slop (~> 3.4)
41
+ rake (10.3.2)
42
+ rb-fsevent (0.9.4)
43
+ rb-inotify (0.9.5)
44
+ ffi (>= 0.5.0)
45
+ rspec (3.1.0)
46
+ rspec-core (~> 3.1.0)
47
+ rspec-expectations (~> 3.1.0)
48
+ rspec-mocks (~> 3.1.0)
49
+ rspec-core (3.1.7)
50
+ rspec-support (~> 3.1.0)
51
+ rspec-expectations (3.1.2)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.1.0)
54
+ rspec-mocks (3.1.3)
55
+ rspec-support (~> 3.1.0)
56
+ rspec-support (3.1.2)
57
+ simplecov (0.9.1)
58
+ docile (~> 1.1.0)
59
+ multi_json (~> 1.0)
60
+ simplecov-html (~> 0.8.0)
61
+ simplecov-html (0.8.0)
62
+ slop (3.6.0)
63
+ thor (0.19.1)
64
+ timers (4.0.1)
65
+ hitimes
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler (~> 1.7)
72
+ guard-rspec
73
+ rake (~> 10.0)
74
+ rpi_marca!
75
+ rspec (~> 3.1)
76
+ simplecov
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(/^spec\/.+_spec\.rb$/)
14
+ watch(/^lib\/(.+)\.rb$/) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { 'spec' }
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Luiz Damim
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # RpiMarca
2
+
3
+ Leitura da RPI de Marcas do INPI em formato XML.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rpi_marca'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rpi_marca
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/automatto/rpi_marca/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
4
+
5
+ task default: :spec
6
+ task test: :spec
@@ -0,0 +1,3 @@
1
+ module RpiMarca
2
+ class ParseError < StandardError; end
3
+ end
@@ -0,0 +1,18 @@
1
+ module RpiMarca
2
+ class Helpers
3
+ def self.get_attribute_value(element, attr)
4
+ return nil unless element
5
+
6
+ value = element[attr]
7
+ value unless value.nil? || value.empty?
8
+ end
9
+
10
+ def self.get_element_value(element)
11
+ return element.text unless element.nil? || element.text == ''
12
+ end
13
+
14
+ def self.parse_date(value)
15
+ Date.strptime(value, '%d/%m/%Y') if value
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ require 'rpi_marca/helpers'
2
+ require 'rpi_marca/publication'
3
+ require 'nokogiri'
4
+
5
+ module RpiMarca
6
+ class Magazine
7
+ include Enumerable
8
+
9
+ attr_reader :number, :date
10
+
11
+ def initialize(src)
12
+ @source = Nokogiri::XML(src).root
13
+
14
+ @number = Helpers.get_attribute_value(@source, 'numero').to_i
15
+ @date = Helpers.parse_date(
16
+ Helpers.get_attribute_value(@source, 'data')
17
+ )
18
+ end
19
+
20
+ def each
21
+ if block_given?
22
+ @source.xpath('//processo').each { |el| yield Publication.new(el) }
23
+ else
24
+ to_enum(:each)
25
+ end
26
+ end
27
+
28
+ def valid?
29
+ schema = File.join(
30
+ File.dirname(File.expand_path(__FILE__)),
31
+ 'magazine.xsd'
32
+ )
33
+
34
+ File.open(schema, 'r') do |f|
35
+ Nokogiri::XML::Schema(f).valid?(@source.document)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,335 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
+ <xs:element name="revista">
4
+ <xs:complexType>
5
+ <xs:sequence>
6
+ <xs:element ref="processo" maxOccurs="unbounded"/>
7
+ </xs:sequence>
8
+ <xs:attribute name="numero" use="required">
9
+ <xs:simpleType>
10
+ <xs:restriction base="xs:nonNegativeInteger">
11
+ <xs:maxInclusive value="9999"/>
12
+ </xs:restriction>
13
+ </xs:simpleType>
14
+ </xs:attribute>
15
+ <xs:attribute name="data" use="required">
16
+ <xs:simpleType>
17
+ <xs:restriction base="xs:string">
18
+ <xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
19
+ </xs:restriction>
20
+ </xs:simpleType>
21
+ </xs:attribute>
22
+ </xs:complexType>
23
+ </xs:element>
24
+ <xs:element name="processo">
25
+ <xs:complexType>
26
+ <xs:sequence>
27
+ <xs:element ref="despachos"/>
28
+ <xs:choice minOccurs="0" maxOccurs="9">
29
+ <xs:element ref="titulares"/>
30
+ <xs:element ref="marca"/>
31
+ <xs:element ref="classes-vienna"/>
32
+ <xs:element ref="classe-nice"/>
33
+ <xs:element ref="apostila"/>
34
+ <xs:element ref="prioridade-unionista"/>
35
+ <xs:element ref="classe-nacional"/>
36
+ <xs:element ref="procurador"/>
37
+ <xs:element ref="sobrestadores"/>
38
+ </xs:choice>
39
+ </xs:sequence>
40
+ <xs:attribute name="numero" use="required">
41
+ <xs:simpleType>
42
+ <xs:restriction base="xs:integer">
43
+ <xs:pattern value="[0-9]{9}"/>
44
+ </xs:restriction>
45
+ </xs:simpleType>
46
+ </xs:attribute>
47
+ <xs:attribute name="data-deposito">
48
+ <xs:simpleType>
49
+ <xs:restriction base="xs:string">
50
+ <xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
51
+ </xs:restriction>
52
+ </xs:simpleType>
53
+ </xs:attribute>
54
+ <xs:attribute name="data-concessao">
55
+ <xs:simpleType>
56
+ <xs:restriction base="xs:string">
57
+ <xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
58
+ </xs:restriction>
59
+ </xs:simpleType>
60
+ </xs:attribute>
61
+ <xs:attribute name="data-vigencia">
62
+ <xs:simpleType>
63
+ <xs:restriction base="xs:string">
64
+ <xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
65
+ </xs:restriction>
66
+ </xs:simpleType>
67
+ </xs:attribute>
68
+ </xs:complexType>
69
+ </xs:element>
70
+ <xs:element name="despachos">
71
+ <xs:complexType>
72
+ <xs:sequence>
73
+ <xs:element ref="despacho" maxOccurs="unbounded"/>
74
+ </xs:sequence>
75
+ </xs:complexType>
76
+ </xs:element>
77
+ <xs:element name="despacho">
78
+ <xs:complexType>
79
+ <xs:sequence>
80
+ <xs:element name="texto-complementar" type="xs:string" minOccurs="0"/>
81
+ <xs:element ref="protocolo" minOccurs="0"/>
82
+ </xs:sequence>
83
+ <xs:attribute name="codigo" use="required">
84
+ <xs:simpleType>
85
+ <xs:restriction base="xs:string">
86
+ <xs:pattern value="IPAS[0-9]{3}"/>
87
+ </xs:restriction>
88
+ </xs:simpleType>
89
+ </xs:attribute>
90
+ <xs:attribute type="xs:string" name="nome" use="required"/>
91
+ </xs:complexType>
92
+ </xs:element>
93
+ <xs:element name="protocolo">
94
+ <xs:complexType>
95
+ <xs:sequence>
96
+ <xs:element ref="requerente" minOccurs="0"/>
97
+ <xs:element ref="procurador" minOccurs="0"/>
98
+ <xs:element ref="cessionario" minOccurs="0"/>
99
+ </xs:sequence>
100
+ <xs:attribute name="numero" use="required">
101
+ <xs:simpleType>
102
+ <xs:restriction base="xs:integer">
103
+ <xs:pattern value="[0-9]{10,}"/>
104
+ </xs:restriction>
105
+ </xs:simpleType>
106
+ </xs:attribute>
107
+ <xs:attribute name="data" use="required">
108
+ <xs:simpleType>
109
+ <xs:restriction base="xs:string">
110
+ <xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
111
+ </xs:restriction>
112
+ </xs:simpleType>
113
+ </xs:attribute>
114
+ <xs:attribute name="codigoServico" use="required">
115
+ <xs:simpleType>
116
+ <xs:restriction base="xs:string">
117
+ <xs:pattern value="[0-9]{4,5}|P[0-9]{2}"/>
118
+ </xs:restriction>
119
+ </xs:simpleType>
120
+ </xs:attribute>
121
+ </xs:complexType>
122
+ </xs:element>
123
+ <xs:element name="titulares">
124
+ <xs:complexType>
125
+ <xs:sequence>
126
+ <xs:element name="titular" maxOccurs="unbounded">
127
+ <xs:complexType>
128
+ <xs:attribute type="xs:string" name="nome-razao-social" use="required"/>
129
+ <xs:attribute name="pais" use="required">
130
+ <xs:simpleType>
131
+ <xs:restriction base="xs:string">
132
+ <xs:pattern value="[A-Z]{2}"/>
133
+ </xs:restriction>
134
+ </xs:simpleType>
135
+ </xs:attribute>
136
+ <xs:attribute name="uf">
137
+ <xs:simpleType>
138
+ <xs:restriction base="xs:string">
139
+ <xs:pattern value="[A-Z]{2}"/>
140
+ </xs:restriction>
141
+ </xs:simpleType>
142
+ </xs:attribute>
143
+ </xs:complexType>
144
+ </xs:element>
145
+ </xs:sequence>
146
+ </xs:complexType>
147
+ </xs:element>
148
+ <xs:element name="marca">
149
+ <xs:complexType>
150
+ <xs:sequence>
151
+ <xs:element name="nome" type="xs:string" minOccurs="0"/>
152
+ </xs:sequence>
153
+ <xs:attribute name="apresentacao" use="required">
154
+ <xs:simpleType>
155
+ <xs:restriction base="xs:string">
156
+ <xs:enumeration value="Nominativa"/>
157
+ <xs:enumeration value="Mista"/>
158
+ <xs:enumeration value="Figurativa"/>
159
+ <xs:enumeration value="Tridimensional"/>
160
+ </xs:restriction>
161
+ </xs:simpleType>
162
+ </xs:attribute>
163
+ <xs:attribute name="natureza" use="required">
164
+ <xs:simpleType>
165
+ <xs:restriction base="xs:string">
166
+ <xs:enumeration value="De Produto"/>
167
+ <xs:enumeration value="De Serviço"/>
168
+ <xs:enumeration value="Coletiva"/>
169
+ <xs:enumeration value="Certificação"/>
170
+ <xs:enumeration value="Certific."/>
171
+ <xs:enumeration value="Genérica"/>
172
+ <xs:enumeration value="Específica"/>
173
+ <xs:enumeration value="Expressão Propaganda"/>
174
+ </xs:restriction>
175
+ </xs:simpleType>
176
+ </xs:attribute>
177
+ </xs:complexType>
178
+ </xs:element>
179
+ <xs:element name="especificacao">
180
+ <xs:simpleType>
181
+ <xs:restriction base="xs:string">
182
+ <xs:minLength value="1"/>
183
+ </xs:restriction>
184
+ </xs:simpleType>
185
+ </xs:element>
186
+ <xs:element name="classes-vienna">
187
+ <xs:complexType>
188
+ <xs:sequence>
189
+ <xs:element ref="classe-vienna" minOccurs="0" maxOccurs="unbounded"/>
190
+ </xs:sequence>
191
+ <xs:attribute type="xs:string" name="edicao" use="required"/>
192
+ </xs:complexType>
193
+ </xs:element>
194
+ <xs:element name="classe-vienna">
195
+ <xs:complexType>
196
+ <xs:simpleContent>
197
+ <xs:extension base="xs:string">
198
+ <xs:attribute type="xs:string" name="codigo" use="required"/>
199
+ </xs:extension>
200
+ </xs:simpleContent>
201
+ </xs:complexType>
202
+ </xs:element>
203
+ <xs:element name="classe-nice">
204
+ <xs:complexType>
205
+ <xs:sequence>
206
+ <xs:element ref="especificacao"/>
207
+ </xs:sequence>
208
+ <xs:attribute name="codigo" use="required">
209
+ <xs:simpleType>
210
+ <xs:restriction base="xs:integer">
211
+ <xs:minInclusive value="01"/>
212
+ <xs:maxInclusive value="45"/>
213
+ </xs:restriction>
214
+ </xs:simpleType>
215
+ </xs:attribute>
216
+ </xs:complexType>
217
+ </xs:element>
218
+ <xs:element name="apostila">
219
+ <xs:simpleType>
220
+ <xs:restriction base="xs:string">
221
+ <xs:minLength value="1"/>
222
+ </xs:restriction>
223
+ </xs:simpleType>
224
+ </xs:element>
225
+ <xs:element name="prioridade-unionista">
226
+ <xs:complexType>
227
+ <xs:sequence>
228
+ <xs:element name="prioridade" maxOccurs="unbounded">
229
+ <xs:complexType>
230
+ <xs:simpleContent>
231
+ <xs:extension base="xs:string">
232
+ <xs:attribute type="xs:string" name="numero" use="required"/>
233
+ <xs:attribute name="data" use="required">
234
+ <xs:simpleType>
235
+ <xs:restriction base="xs:string">
236
+ <xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
237
+ </xs:restriction>
238
+ </xs:simpleType>
239
+ </xs:attribute>
240
+ <xs:attribute name="pais" use="required">
241
+ <xs:simpleType>
242
+ <xs:restriction base="xs:string">
243
+ <xs:pattern value="[A-Z]{2}"/>
244
+ </xs:restriction>
245
+ </xs:simpleType>
246
+ </xs:attribute>
247
+ </xs:extension>
248
+ </xs:simpleContent>
249
+ </xs:complexType>
250
+ </xs:element>
251
+ </xs:sequence>
252
+ </xs:complexType>
253
+ </xs:element>
254
+ <xs:element name="classe-nacional">
255
+ <xs:complexType>
256
+ <xs:sequence>
257
+ <xs:element ref="especificacao"/>
258
+ <xs:element ref="sub-classes-nacional"/>
259
+ </xs:sequence>
260
+ <xs:attribute name="codigo" use="required">
261
+ <xs:simpleType>
262
+ <xs:restriction base="xs:integer">
263
+ <xs:minInclusive value="01"/>
264
+ <xs:maxInclusive value="43"/>
265
+ </xs:restriction>
266
+ </xs:simpleType>
267
+ </xs:attribute>
268
+ </xs:complexType>
269
+ </xs:element>
270
+ <xs:element name="sub-classes-nacional">
271
+ <xs:complexType>
272
+ <xs:sequence>
273
+ <xs:element name="sub-classe-nacional" maxOccurs="3">
274
+ <xs:complexType>
275
+ <xs:simpleContent>
276
+ <xs:extension base="xs:string">
277
+ <xs:attribute name="codigo" use="required">
278
+ <xs:simpleType>
279
+ <xs:restriction base="xs:integer">
280
+ <xs:totalDigits value="2"/>
281
+ </xs:restriction>
282
+ </xs:simpleType>
283
+ </xs:attribute>
284
+ </xs:extension>
285
+ </xs:simpleContent>
286
+ </xs:complexType>
287
+ </xs:element>
288
+ </xs:sequence>
289
+ </xs:complexType>
290
+ </xs:element>
291
+ <xs:element name="procurador" type="xs:string"/>
292
+ <xs:element name="requerente">
293
+ <xs:complexType>
294
+ <xs:simpleContent>
295
+ <xs:extension base="xs:string">
296
+ <xs:attribute type="xs:string" name="nome-razao-social" use="required"/>
297
+ <xs:attribute type="xs:string" name="pais"/>
298
+ <xs:attribute type="xs:string" name="uf"/>
299
+ </xs:extension>
300
+ </xs:simpleContent>
301
+ </xs:complexType>
302
+ </xs:element>
303
+ <xs:element name="cessionario">
304
+ <xs:complexType>
305
+ <xs:simpleContent>
306
+ <xs:extension base="xs:string">
307
+ <xs:attribute type="xs:string" name="nome-razao-social" use="required"/>
308
+ </xs:extension>
309
+ </xs:simpleContent>
310
+ </xs:complexType>
311
+ </xs:element>
312
+ <xs:element name="sobrestadores">
313
+ <xs:complexType>
314
+ <xs:sequence>
315
+ <xs:element ref="sobrestador" maxOccurs="unbounded"/>
316
+ </xs:sequence>
317
+ </xs:complexType>
318
+ </xs:element>
319
+ <xs:element name="sobrestador">
320
+ <xs:complexType>
321
+ <xs:simpleContent>
322
+ <xs:extension base="xs:string">
323
+ <xs:attribute name="processo" use="required">
324
+ <xs:simpleType>
325
+ <xs:restriction base="xs:integer">
326
+ <xs:pattern value="[0-9]{9}"/>
327
+ </xs:restriction>
328
+ </xs:simpleType>
329
+ </xs:attribute>
330
+ <xs:attribute type="xs:string" name="marca"/>
331
+ </xs:extension>
332
+ </xs:simpleContent>
333
+ </xs:complexType>
334
+ </xs:element>
335
+ </xs:schema>
@@ -0,0 +1,46 @@
1
+ module RpiMarca
2
+ class NationalClass
3
+ attr_reader :number, :subclass1, :subclass2, :subclass3, :goods_services
4
+
5
+ def initialize(number:, subclass1:, subclass2:, subclass3:,
6
+ goods_services:)
7
+ fail ParseError, "National class #{classe} out of range (1-41)" unless
8
+ (1..41).include?(number.to_i)
9
+
10
+ @number = number
11
+ @subclass1 = subclass1 if subclass1 > 0
12
+ @subclass2 = subclass2 if subclass2 > 0
13
+ @subclass3 = subclass3 if subclass3 > 0
14
+ @goods_services = goods_services
15
+ end
16
+
17
+ def self.parse(el)
18
+ return unless el
19
+
20
+ subclass = parse_subclass(el)
21
+
22
+ new(
23
+ number: Helpers.get_attribute_value(el, 'codigo').to_i,
24
+ **subclass,
25
+ goods_services: Helpers.get_element_value(
26
+ el.at_xpath('.//especificacao')
27
+ )
28
+ )
29
+ end
30
+
31
+ def self.parse_subclass(el)
32
+ subclass = el.xpath('.//sub-classe-nacional').map { |s| s['codigo'] }
33
+ fail ParseError, "National class can't have more than 3 subclasses" if
34
+ subclass.length > 3
35
+
36
+ {
37
+ subclass1: subclass[0].to_i,
38
+ subclass2: subclass[1].to_i,
39
+ subclass3: subclass[2].to_i
40
+
41
+ }
42
+ end
43
+
44
+ private_class_method :parse_subclass
45
+ end
46
+ end