gotime-slither 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3d2ee3717c7e3ed3187c30b6f5913f15ca2d382
4
- data.tar.gz: c941cd80a505c801172bf0377343b27064df2eb0
3
+ metadata.gz: 99ab6bb56013c690a945d6621bfba1a39beb78a3
4
+ data.tar.gz: 8195f0c7272a6b8988d8ecf502a47aaa67ce7d6e
5
5
  SHA512:
6
- metadata.gz: 2ab17161a128a546574ea4f1cd2b5be6f39363005c7578a0eb758a381e0d2afa1a8eba1c0bf421d233e456dd9396cf43429fd7434bb52a4d8accffde40e4894e
7
- data.tar.gz: 3b9c5d9746c2cb86b943efdcbeb0871f93de2b7509cbb5e86d04f1ca253acd3299dc277618e8d84c57d1f312dfc4657e1a5788aee0d79337200bb0238e87a292
6
+ metadata.gz: fc74901e7d3c703c87c0a37716f906a4f33ca6bec64407c424e2d233d4c04296237cfc3de4ca87d8eb1f5f17ec80017e2ea4118c7ced1927676c21d515823753
7
+ data.tar.gz: b9159e5c9d546abcb62a22469e765781558770fad136bbc76f1e9daea891e79bae14f7ab4cd193658e95f3a244c085cf06b0514ef297da34c6f7c5260403a734
@@ -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.parseIo(io_object, :simple)
79
+ parsed_data = Slither.parse_io(io_object, :simple)
80
80
 
81
81
 
82
82
  == INSTALL:
Binary file
@@ -8,29 +8,20 @@ class Slither
8
8
  @mode = :linear
9
9
  end
10
10
 
11
- def parse(error_handler=nil)
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, error_handler) if @definition.options[:validate_length]
20
- parsed = fill_content(line, section, parsed)
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
- parsed = fill_content(record, section, parsed)
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, error_handler)
49
+ def validate_length(line, section)
70
50
  if line.length != section.length
71
- if error_handler
72
- error_handler.call(line)
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
 
@@ -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
- parseIo(file_io, definition_name)
38
+ parse_io(file_io, definition_name, &block)
39
39
  end
40
40
 
41
- def self.parseIo(io, definition_name)
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(definition.options[:error_handler])
45
+ definition.options[:by_bytes] ? parser.parse_by_bytes(&block) : parser.parse(&block)
46
46
  end
47
47
 
48
48
  private
@@ -107,7 +107,7 @@ describe Slither::Parser do
107
107
  :body => [ {:first => utf_str1, :last => utf_str2} ]
108
108
  }
109
109
 
110
- Slither.parseIo(@io, :test).should eq(expected)
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.parseIo(@io, :test).should eq(expected)
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.parseIo(@io, :test).should eq(expected)
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.parseIo(@io, :test).should eq(expected)
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.parseIo(@io, :test).should eq(expected)
219
+ Slither.parse_io(@io, :test).should eq(expected)
220
220
  end
221
221
  end
222
222
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotime-slither
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wood