Module: Hippo::Separator
- Included in:
- Parser, Hippo::Segments::Base, TransactionSets::Base
- Defined in:
- lib/hippo/separator.rb
Instance Attribute Summary collapse
-
#composite_separator ⇒ Object
Returns the value of attribute composite_separator.
-
#field_separator ⇒ Object
Returns the value of attribute field_separator.
-
#repetition_separator ⇒ Object
Returns the value of attribute repetition_separator.
-
#segment_separator ⇒ Object
Returns the value of attribute segment_separator.
Instance Method Summary collapse
- #empty_field_regexp ⇒ Object
- #initialize(options = {}) ⇒ Object
- #parent_or_default_separator(separator_type) ⇒ Object
- #parse_separators(input) ⇒ Object
- #remove_empty_fields(input) ⇒ Object
- #repeating_composite_separator_regexp ⇒ Object
- #repeating_field_separator_at_end_of_segment_regexp ⇒ Object
- #separators ⇒ Object
Instance Attribute Details
#composite_separator ⇒ Object
Returns the value of attribute composite_separator.
8 9 10 |
# File 'lib/hippo/separator.rb', line 8 def composite_separator @composite_separator end |
#field_separator ⇒ Object
Returns the value of attribute field_separator.
8 9 10 |
# File 'lib/hippo/separator.rb', line 8 def field_separator @field_separator end |
#repetition_separator ⇒ Object
Returns the value of attribute repetition_separator.
8 9 10 |
# File 'lib/hippo/separator.rb', line 8 def repetition_separator @repetition_separator end |
#segment_separator ⇒ Object
Returns the value of attribute segment_separator.
8 9 10 |
# File 'lib/hippo/separator.rb', line 8 def segment_separator @segment_separator end |
Instance Method Details
#empty_field_regexp ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hippo/separator.rb', line 58 def empty_field_regexp %r{([ #{Regexp.escape(@composite_separator)} #{Regexp.escape(@field_separator)} #{Regexp.escape(@segment_separator)} ]) \s+ ([ #{Regexp.escape(@composite_separator)} #{Regexp.escape(@field_separator)} #{Regexp.escape(@segment_separator)} ]) }x end |
#initialize(options = {}) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/hippo/separator.rb', line 10 def initialize( = {}) [:field_separator, :repetition_separator, :composite_separator, :segment_separator].each do |sym| value = [sym] || parent_or_default_separator(sym) self.send(:"#{sym}=", value) end end |
#parent_or_default_separator(separator_type) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/hippo/separator.rb', line 18 def parent_or_default_separator(separator_type) if defined?(parent) && parent parent.send(separator_type.to_sym) else Hippo.const_get(:"DEFAULT_#{separator_type.to_s.upcase}") end end |
#parse_separators(input) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/hippo/separator.rb', line 26 def parse_separators(input) if input =~ /\AISA/ @field_separator = input[3,1] @repetition_separator = input[82,1] @composite_separator = input[104,1] @segment_separator = input[105,1] end end |
#remove_empty_fields(input) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/hippo/separator.rb', line 73 def remove_empty_fields(input) while input =~ empty_field_regexp input = input.gsub(empty_field_regexp, '\1\2') end input end |
#repeating_composite_separator_regexp ⇒ Object
51 52 53 54 55 56 |
# File 'lib/hippo/separator.rb', line 51 def repeating_composite_separator_regexp %r{ #{Regexp.escape(@composite_separator)}+ #{Regexp.escape(@field_separator)} }x end |
#repeating_field_separator_at_end_of_segment_regexp ⇒ Object
44 45 46 47 48 49 |
# File 'lib/hippo/separator.rb', line 44 def repeating_field_separator_at_end_of_segment_regexp %r{ #{Regexp.escape(@field_separator)}+ #{Regexp.escape(@segment_separator)} }x end |
#separators ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/hippo/separator.rb', line 35 def separators { :field_separator => @field_separator, :composite_separator => @composite_separator, :segment_separator => @segment_separator, :repetition_separator => @repetition_separator } end |