hippo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.1.1 - 2012/01/11
2
+ * Update Parser to better handle Loops and repeating components.
3
+ * Flesh out to_html outputter with a basic layout.
1
4
  0.1.0 - 2012/01/05
2
5
  * Add concept of Outputters.
3
6
  * Create PDF and HTML outputters.
@@ -4,5 +4,6 @@ module Hippo
4
4
 
5
5
  class InvalidField < Exception; end
6
6
  class InvalidSegment < Exception; end
7
+ class ParseError < Exception; end
7
8
  end
8
9
  end
@@ -2,11 +2,31 @@ module Hippo::Outputters
2
2
  module HTML
3
3
  module TransactionSet
4
4
  def to_html
5
+ output = ''
6
+ initial_call = caller.select{|m| m =~ /#{__FILE__}/}.length == 0
7
+
8
+ if initial_call
9
+ output = %{<fieldset class="hippo-transaction-set"><legend>#{self.class.to_s.sub('Hippo::TransactionSets::','')}</legend>}
10
+ end
11
+
12
+ values.sort.each do |sequence, component|
13
+ component_definition = self.class.components[sequence]
14
+ if component_definition.klass.ancestors.include?(Hippo::TransactionSets::Base)
15
+ output += %Q{<fieldset class="hippo-component"><legend>#{component_definition.klass.to_s.sub('Hippo::TransactionSets::','')} - #{component_definition.options[:name]}</legend>}
16
+ output += component.to_html
17
+ output += '</fieldset>'
18
+ else
19
+ output += %Q{<span class="hippo-segment-name">#{component_definition.options[:name]}</span><span class="hippo-segment-data">#{component.to_s}</span><br/>}
20
+ end
21
+ end
22
+
23
+ output + (initial_call ? '</fieldset>' : '')
5
24
  end
6
25
  end
7
26
 
8
27
  module Segment
9
28
  def to_html
29
+ to_s
10
30
  end
11
31
  end
12
32
  end
@@ -33,6 +33,7 @@ module Hippo
33
33
  def parse(input)
34
34
  read(input)
35
35
  populate(segments)
36
+ self
36
37
  end
37
38
  end
38
39
  end
data/lib/hippo/parser.rb CHANGED
@@ -43,7 +43,7 @@ module Hippo
43
43
  parse_transaction_sets.collect do |transaction|
44
44
  transaction_set_id = transaction[:segments].first.ST01
45
45
  transaction_set = Hippo::TransactionSets.constants.select{|c| c.to_s.end_with?(transaction_set_id) }.first
46
- binding.pry if transaction_set.nil?
46
+
47
47
  Hippo::TransactionSets.const_get(transaction_set)::Base.new(separators.merge(transaction))
48
48
  end
49
49
  end
@@ -59,41 +59,34 @@ module Hippo::TransactionSets
59
59
  else
60
60
  # loops
61
61
  while true do
62
- found_next_segment = false
63
- starting_index = nil
64
- ending_index = nil
65
- length = 0
62
+ initial_segment = segments.first
66
63
 
67
- starting_index = segments.find_index{|segment| component.valid? segment}
64
+ break unless initial_segment
65
+ break unless component.valid?(initial_segment)
68
66
 
69
- # if we don't find anything break out of the loop
70
- break unless starting_index
71
-
72
- remaining_components = self.class.components.slice(component_index, self.class.components.length - component_index)
67
+ ending_index = nil
68
+ starting_index = component.repeating? ? component_index : component_index + 1
69
+ remaining_components = self.class.components.slice(starting_index, self.class.components.length - starting_index)
73
70
  remaining_components.each do |next_component|
74
71
  break if ending_index
75
72
 
76
- ending_index = segments.find_index{|segment| segment != segments[starting_index] && next_component.valid?(segment)}
73
+ ending_index = segments.find_index{|segment| segment != segments.first && next_component.valid?(segment)}
77
74
  end
78
75
 
79
- length = (ending_index || segments.length) - starting_index
80
-
76
+ child_segments = segments.slice!(0, ending_index || segments.length)
77
+ values[component.sequence] ||= component.initialize_component(self)
81
78
  if component.repeating?
82
- values[component.sequence] ||= component.initialize_component(self)
83
- values[component.sequence].build do |subcomponent|
84
- subcomponent.populate(segments.slice!(starting_index, length))
85
- end
79
+ values[component.sequence].build {|comp| comp.populate(child_segments) }
86
80
  else
87
- subcomponent = component.initialize_component(self)
88
- subcomponent.populate(segments.slice!(starting_index, length))
89
-
90
- values[component.sequence] = subcomponent
81
+ values[component.sequence].populate(child_segments)
91
82
  end
92
83
  end
93
84
  end
94
85
  end
95
86
 
96
- puts "Remaining Segments(#{self.class.identifier}): " + segments.inspect unless segments.empty?
87
+ unless segments.empty?
88
+ raise Hippo::Exceptions::ParseError.new "Remaining Segments for #{self.class.identifier} after parsing was completed. Segments remaining: \n" + segments.map(&:to_s).join("\n")
89
+ end
97
90
  end
98
91
 
99
92
  def values
@@ -18,6 +18,8 @@ module Hippo::TransactionSets
18
18
  end
19
19
 
20
20
  def segment_count
21
+ return 0 unless self.length != 0
22
+
21
23
  self.map(&:segment_count).inject(&:+)
22
24
  end
23
25
 
data/lib/hippo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hippo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('test_helper', File.dirname(__FILE__))
2
+
3
+ class TestHTMLOutputter < MiniTest::Unit::TestCase
4
+ def setup
5
+ @parser = Hippo::Parser.new
6
+ @sample_835 = @parser.parse_file('samples/005010X221A1_business_scenario_1.edi').first
7
+ @sample_837 = @parser.parse_file('samples/005010X231A1_01.edi').first
8
+ end
9
+
10
+ def test_segment_to_html_returns_segment_to_s
11
+ assert_equal @sample_835.BPR.to_s, @sample_835.BPR.to_html
12
+ end
13
+
14
+ def test_transaction_to_html_returns_string
15
+ File.open('/Users/rjackson/Desktop/sample835.html', 'w') {|f| f.write(@sample_835.to_html) }
16
+ File.open('/Users/rjackson/Desktop/sample837.html', 'w') {|f| f.write(@sample_837.to_html) }
17
+ assert_kind_of String, @sample_835.to_html
18
+ end
19
+ end
metadata CHANGED
@@ -1,64 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hippo
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Robert Jackson
14
9
  - Jon Jackson
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-01-05 00:00:00 -05:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-01-11 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: minitest
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70103895950640 !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
34
23
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70103895950640
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &70103895950140 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
30
+ requirements:
42
31
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 63
45
- segments:
46
- - 0
47
- - 9
48
- - 2
32
+ - !ruby/object:Gem::Version
49
33
  version: 0.9.2
50
34
  type: :development
51
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: *70103895950140
52
37
  description: HIPAA Transaction Set Generator/Parser
53
- email:
38
+ email:
54
39
  - robertj@promedicalinc.com
55
40
  executables: []
56
-
57
41
  extensions: []
58
-
59
42
  extra_rdoc_files: []
60
-
61
- files:
43
+ files:
62
44
  - .gitignore
63
45
  - CHANGELOG
64
46
  - Gemfile
@@ -276,47 +258,39 @@ files:
276
258
  - test/test_helper.rb
277
259
  - test/test_hipaa_835.rb
278
260
  - test/test_hipaa_837.rb
261
+ - test/test_html_outputter.rb
279
262
  - test/test_parser.rb
280
263
  - test/test_segments_base.rb
281
264
  - test/test_transaction_sets_base.rb
282
- has_rdoc: true
283
265
  homepage: http://github.com/promedical/hippo
284
266
  licenses: []
285
-
286
267
  post_install_message:
287
268
  rdoc_options: []
288
-
289
- require_paths:
269
+ require_paths:
290
270
  - lib
291
- required_ruby_version: !ruby/object:Gem::Requirement
271
+ required_ruby_version: !ruby/object:Gem::Requirement
292
272
  none: false
293
- requirements:
294
- - - ">="
295
- - !ruby/object:Gem::Version
296
- hash: 3
297
- segments:
298
- - 0
299
- version: "0"
300
- required_rubygems_version: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - ! '>='
275
+ - !ruby/object:Gem::Version
276
+ version: '0'
277
+ required_rubygems_version: !ruby/object:Gem::Requirement
301
278
  none: false
302
- requirements:
303
- - - ">="
304
- - !ruby/object:Gem::Version
305
- hash: 3
306
- segments:
307
- - 0
308
- version: "0"
279
+ requirements:
280
+ - - ! '>='
281
+ - !ruby/object:Gem::Version
282
+ version: '0'
309
283
  requirements: []
310
-
311
284
  rubyforge_project: hippo
312
- rubygems_version: 1.6.2
285
+ rubygems_version: 1.8.11
313
286
  signing_key:
314
287
  specification_version: 3
315
288
  summary: HIPAA Transaction Set Generator/Parser
316
- test_files:
289
+ test_files:
317
290
  - test/test_helper.rb
318
291
  - test/test_hipaa_835.rb
319
292
  - test/test_hipaa_837.rb
293
+ - test/test_html_outputter.rb
320
294
  - test/test_parser.rb
321
295
  - test/test_segments_base.rb
322
296
  - test/test_transaction_sets_base.rb