Class: DynamicFieldGenerator

Inherits:
BaseFieldGenerator show all
Includes:
Utils
Defined in:
lib/ez7gen/service/2.4/dynamic_field_generator.rb

Constant Summary

Constants included from Utils

Utils::BASE, Utils::BASE_INDICATOR, Utils::DATA_LOOKUP_MIS, Utils::PRIMARY

Instance Attribute Summary

Attributes inherited from BaseFieldGenerator

#pp, #yml

Instance Method Summary collapse

Methods included from Utils

#blank?, #get_name_without_base, #get_segment_name, #get_type_by_name, #has_html_encoded_ch?, #is_number?, #num_to_nil, #safe_len, #sample_index

Methods inherited from BaseFieldGenerator

#AD, #CE, #DT, #DTM, #FN, #FT, #GTS, #ID, #IS, #NM, #SAD, #SI, #ST, #TM, #TN, #TS, #TX, #apply_rules, #generate?, #generate_length_bound_id, #get_code_table, #get_coded_map, #get_coded_value, #handle_length, #handle_ranges, #reset_map_attr, #to_datetime

Constructor Details

#initialize(pp) ⇒ DynamicFieldGenerator

constructor



9
10
11
# File 'lib/ez7gen/service/2.4/dynamic_field_generator.rb', line 9

def initialize(pp)
  super pp
end

Instance Method Details

#dynamic(name, map, force = false) ⇒ Object

base data types [“DT”, “FT”, “ID”, “IS”, “NM”, “SI”, “ST”, “TM”, “TN”, “TX”]



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ez7gen/service/2.4/dynamic_field_generator.rb', line 15

def dynamic(name, map, force=false)
  #check if the field is optional and randomly generate it of skip
  return '' if(!generate?(map, force))
  sub_types = []
  value = []

  @pp.xml.Export.Document.Category.locate('DataType').select{|it| it.attributes[:name] == name}.first.locate('DataSubType').each{ |it| sub_types << it.attributes}

  sub_types.each{ |sub_type|
    # check if field is required
   begin
    value << method(sub_type[:datatype]).call(sub_type,true)
   rescue NameError => e
     # puts e
     $log.error("#{self.class.to_s}:#{__method__.to_s}") { e.message }
     sub_values = dynamic(sub_type[:datatype], sub_type, true)

     # TODO :remove trailing empty fields
     # TODO: handle fields and subfields if it deeper then 3 levels in DR : "761&663^753&799"
     value << sub_values.gsub(@@HAT,@@SUB)
     puts sub_values
   end
  }

  return value.join(@@HAT)
end