gotime-slither 1.0.2 → 1.0.3
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 +4 -4
- data/README.rdoc +1 -1
- data/gotime-slither.gemspec +0 -0
- data/lib/slither/parser.rb +7 -31
- data/lib/slither/slither.rb +4 -4
- data/spec/parser_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99ab6bb56013c690a945d6621bfba1a39beb78a3
|
4
|
+
data.tar.gz: 8195f0c7272a6b8988d8ecf502a47aaa67ce7d6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc74901e7d3c703c87c0a37716f906a4f33ca6bec64407c424e2d233d4c04296237cfc3de4ca87d8eb1f5f17ec80017e2ea4118c7ced1927676c21d515823753
|
7
|
+
data.tar.gz: b9159e5c9d546abcb62a22469e765781558770fad136bbc76f1e9daea891e79bae14f7ab4cd193658e95f3a244c085cf06b0514ef297da34c6f7c5260403a734
|
data/README.rdoc
CHANGED
@@ -76,7 +76,7 @@ Then either feed it a nested struct with data values to create the file in the d
|
|
76
76
|
or parse files already in that format into a nested hash:
|
77
77
|
|
78
78
|
parsed_data = Slither.parse(input_filename, :simple)
|
79
|
-
parsed_data = Slither.
|
79
|
+
parsed_data = Slither.parse_io(io_object, :simple)
|
80
80
|
|
81
81
|
|
82
82
|
== INSTALL:
|
data/gotime-slither.gemspec
CHANGED
Binary file
|
data/lib/slither/parser.rb
CHANGED
@@ -8,29 +8,20 @@ class Slither
|
|
8
8
|
@mode = :linear
|
9
9
|
end
|
10
10
|
|
11
|
-
def parse
|
12
|
-
parsed = {}
|
13
|
-
|
11
|
+
def parse
|
14
12
|
@file.each_line do |line|
|
15
13
|
line.chomp! if line
|
16
14
|
next if line.empty?
|
17
15
|
@definition.sections.each do |section|
|
18
16
|
if section.match(line)
|
19
|
-
validate_length(line, section
|
20
|
-
|
17
|
+
validate_length(line, section) if @definition.options[:validate_length]
|
18
|
+
yield section.parse(line)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
24
|
-
|
25
|
-
@definition.sections.each do |section|
|
26
|
-
raise(Slither::RequiredSectionNotFoundError, "Required section '#{section.name}' was not found.") unless parsed[section.name] || section.optional
|
27
|
-
end
|
28
|
-
parsed
|
29
22
|
end
|
30
23
|
|
31
24
|
def parse_by_bytes
|
32
|
-
parsed = {}
|
33
|
-
|
34
25
|
all_section_lengths = @definition.sections.map{|sec| sec.length }
|
35
26
|
byte_length = all_section_lengths.max
|
36
27
|
all_section_lengths.each { |bytes| raise(Slither::SectionsNotSameLengthError,
|
@@ -47,33 +38,18 @@ class Slither
|
|
47
38
|
|
48
39
|
@definition.sections.each do |section|
|
49
40
|
if section.match(record)
|
50
|
-
|
41
|
+
yield section.parse(record)
|
51
42
|
end
|
52
43
|
end
|
53
44
|
end
|
54
|
-
|
55
|
-
@definition.sections.each do |section|
|
56
|
-
raise(Slither::RequiredSectionNotFoundError, "Required section '#{section.name}' was not found.") unless parsed[section.name] || section.optional
|
57
|
-
end
|
58
|
-
parsed
|
59
45
|
end
|
60
46
|
|
61
47
|
private
|
62
|
-
|
63
|
-
def fill_content(line, section, parsed)
|
64
|
-
parsed[section.name] ||= []
|
65
|
-
parsed[section.name] << section.parse(line)
|
66
|
-
parsed
|
67
|
-
end
|
68
48
|
|
69
|
-
def validate_length(line, section
|
49
|
+
def validate_length(line, section)
|
70
50
|
if line.length != section.length
|
71
|
-
|
72
|
-
|
73
|
-
else
|
74
|
-
parsed_line = parse_for_error_message(line)
|
75
|
-
raise Slither::LineWrongSizeError, "Line wrong size: (#{line.length} when it should be #{section.length}. #{parsed_line})"
|
76
|
-
end
|
51
|
+
parsed_line = parse_for_error_message(line)
|
52
|
+
raise Slither::LineWrongSizeError, "Line wrong size: (#{line.length} when it should be #{section.length}. #{parsed_line})"
|
77
53
|
end
|
78
54
|
end
|
79
55
|
|
data/lib/slither/slither.rb
CHANGED
@@ -31,18 +31,18 @@ class Slither
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.parse(filename, definition_name)
|
34
|
+
def self.parse(filename, definition_name, &block)
|
35
35
|
raise ArgumentError, "File #{filename} does not exist." unless File.exists?(filename)
|
36
36
|
|
37
37
|
file_io = File.open(filename, 'r')
|
38
|
-
|
38
|
+
parse_io(file_io, definition_name, &block)
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.
|
41
|
+
def self.parse_io(io, definition_name, &block)
|
42
42
|
definition = definition(definition_name)
|
43
43
|
raise ArgumentError, "Definition name '#{definition_name}' was not found." unless definition
|
44
44
|
parser = Parser.new(definition, io)
|
45
|
-
definition.options[:by_bytes] ? parser.parse_by_bytes : parser.parse(
|
45
|
+
definition.options[:by_bytes] ? parser.parse_by_bytes(&block) : parser.parse(&block)
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
data/spec/parser_spec.rb
CHANGED
@@ -107,7 +107,7 @@ describe Slither::Parser do
|
|
107
107
|
:body => [ {:first => utf_str1, :last => utf_str2} ]
|
108
108
|
}
|
109
109
|
|
110
|
-
Slither.
|
110
|
+
Slither.parse_io(@io, :test).should eq(expected)
|
111
111
|
end
|
112
112
|
|
113
113
|
end
|
@@ -153,7 +153,7 @@ describe Slither::Parser do
|
|
153
153
|
:body => [ {:first => utf_str1, :last => utf_str2} ]
|
154
154
|
}
|
155
155
|
|
156
|
-
Slither.
|
156
|
+
Slither.parse_io(@io, :test).should eq(expected)
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'should handle mid-line newline chars' do
|
@@ -165,7 +165,7 @@ describe Slither::Parser do
|
|
165
165
|
:body => [ {:first => str1, :last => str2}, {:first => str1, :last => str2} ]
|
166
166
|
}
|
167
167
|
|
168
|
-
Slither.
|
168
|
+
Slither.parse_io(@io, :test).should eq(expected)
|
169
169
|
end
|
170
170
|
|
171
171
|
it 'should throw exception if section lengths are different' do
|
@@ -206,7 +206,7 @@ describe Slither::Parser do
|
|
206
206
|
:body => [ {:first => 'abc', :dat => [0x00, 0x18], :last => 'end'} ]
|
207
207
|
}
|
208
208
|
|
209
|
-
Slither.
|
209
|
+
Slither.parse_io(@io, :test).should eq(expected)
|
210
210
|
end
|
211
211
|
|
212
212
|
it 'should handle spaces' do
|
@@ -216,7 +216,7 @@ describe Slither::Parser do
|
|
216
216
|
:body => [ {:first => 'abc', :dat => [0x20, 0x18], :last => 'end'} ]
|
217
217
|
}
|
218
218
|
|
219
|
-
Slither.
|
219
|
+
Slither.parse_io(@io, :test).should eq(expected)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|