Class: EDI::E::UNA

Inherits:
Object show all
Defined in:
lib/edi4r/edifact.rb

Overview

Class UNA is a model of UN/EDIFACT's UNA pseudo-segment. It provides getters and setters that let you manipulate the six special characters of UN/EDIFACT. Note that the chars are passed as integers, i.e. ASCII codes.

Instance Attribute Summary collapse

Attributes inherited from Object

#name, #parent, #root

Instance Method Summary collapse

Constructor Details

#initialize(root, source = nil) ⇒ UNA

Generates the UNA object

  • Requires that “version” and “charset” of parent/root (Interchange) be already defined.

  • Sets the UN/EDIFACT defaults if source string 'UNA.…..' not given


295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/edi4r/edifact.rb', line 295

def initialize( root, source=nil )
  super( root, root, 'UNA')

  raise "UNA.new requires 'version' in the interchange" unless root.version
  raise "UNA.new requires 'charset' in the interchange" unless root.charset

  if source =~ /^UNA(......)$/  # Take what's given
    @chars = $1

  elsif (source == nil or source.empty?) # Use EDIFACT default rules
    if root.version==2 and root.charset=='UNOB'
      @chars = "\x11\x12.? \x14"
    elsif root.version==4
      @chars = ":+.?*'"
    else
      @chars = ":+.? '"
    end

  else
    raise "This is not a valid UNA source string: #{source}"
  end

  @ce_sep, @de_sep, @decimal_sign,
  @esc_char, @rep_sep, @seg_term = @chars.split('').map{|c| c[0]}
  set_patterns
end

Instance Attribute Details

#ce_sepObject

Returns the value of attribute ce_sep


230
231
232
# File 'lib/edi4r/edifact.rb', line 230

def ce_sep
  @ce_sep
end

#de_sepObject

Returns the value of attribute de_sep


230
231
232
# File 'lib/edi4r/edifact.rb', line 230

def de_sep
  @de_sep
end

#decimal_signObject

Returns the value of attribute decimal_sign


230
231
232
# File 'lib/edi4r/edifact.rb', line 230

def decimal_sign
  @decimal_sign
end

#esc_charObject

Returns the value of attribute esc_char


230
231
232
# File 'lib/edi4r/edifact.rb', line 230

def esc_char
  @esc_char
end

#pattern_escObject (readonly)

:nodoc:


229
230
231
# File 'lib/edi4r/edifact.rb', line 229

def pattern_esc
  @pattern_esc
end

#pattern_unescObject (readonly)

:nodoc:


229
230
231
# File 'lib/edi4r/edifact.rb', line 229

def pattern_unesc
  @pattern_unesc
end

#rep_sepObject

Returns the value of attribute rep_sep


230
231
232
# File 'lib/edi4r/edifact.rb', line 230

def rep_sep
  @rep_sep
end

#seg_termObject

Returns the value of attribute seg_term


230
231
232
# File 'lib/edi4r/edifact.rb', line 230

def seg_term
  @seg_term
end

Instance Method Details

#to_sObject


322
323
324
# File 'lib/edi4r/edifact.rb', line 322

def to_s
  'UNA'+@chars
end