Class: Translator
Instance Attribute Summary collapse
-
#data_in ⇒ Object
Returns the value of attribute data_in.
-
#data_out ⇒ Object
Returns the value of attribute data_out.
-
#reference_path ⇒ Object
Returns the value of attribute reference_path.
Instance Method Summary collapse
- #deep_add_merge(struct, subnode, addon) ⇒ Object
- #deep_copy(o) ⇒ Object
-
#initialize(node, logger: nil) ⇒ Translator
constructor
A new instance of Translator.
-
#merge_by_add(struct) ⇒ Object
perform merge by “__add__” node only applys to application type.
- #translate ⇒ Object
Methods included from Utils_set
Constructor Details
#initialize(node, logger: nil) ⇒ Translator
Returns a new instance of Translator.
21 22 23 24 25 26 |
# File 'lib/ebngen/translate.rb', line 21 def initialize(node, logger: nil) @data_in = deep_copy(node) @data_in_component = deep_copy(node) @data_out = Hash.new merge_by_add(@data_in) end |
Instance Attribute Details
#data_in ⇒ Object
Returns the value of attribute data_in.
17 18 19 |
# File 'lib/ebngen/translate.rb', line 17 def data_in @data_in end |
#data_out ⇒ Object
Returns the value of attribute data_out.
17 18 19 |
# File 'lib/ebngen/translate.rb', line 17 def data_out @data_out end |
#reference_path ⇒ Object
Returns the value of attribute reference_path.
17 18 19 |
# File 'lib/ebngen/translate.rb', line 17 def reference_path @reference_path end |
Instance Method Details
#deep_add_merge(struct, subnode, addon) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ebngen/translate.rb', line 32 def deep_add_merge(struct, subnode, addon) return if Hash != struct.class if struct[addon]['__add__'].nil? #we do not want the addon module to change the status struct[addon]['attribute'] = "" struct[subnode] = struct[subnode].deep_merge(deep_copy(struct[addon])) struct[addon]['attribute'] = 'required' return end #if has more addon if struct[addon]['__add__'].count != 0 struct[addon]['__add__'].each do |submodule| deep_add_merge(struct, addon, submodule) end else struct[addon]['attribute'] = "" struct[subnode] = struct[subnode].deep_merge(deep_copy(struct[addon])) struct[addon]['attribute'] = 'required' end end |
#deep_copy(o) ⇒ Object
28 29 30 |
# File 'lib/ebngen/translate.rb', line 28 def deep_copy(o) Marshal.load(Marshal.dump(o)) end |
#merge_by_add(struct) ⇒ Object
perform merge by “__add__” node only applys to application type
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ebngen/translate.rb', line 54 def merge_by_add(struct) #only scan the top level return if Hash != struct.class struct.each_key do |subnode| if struct[subnode]['__add__'] != nil struct[subnode]['__add__'].each do |addon| next if struct[addon].class != Hash begin next if struct[subnode]['configuration']['section-type'] != "application" if struct[addon]['configuration']['section-type'] != "component" puts "WARNING #{addon} is required as component but has not a component attribute" end rescue puts "error with the merge_by_add with #{subnode} add #{addon}" end deep_add_merge(struct, subnode, addon) end #struct[subnode].delete('__add__') end end end |
#translate ⇒ Object
76 77 78 79 80 |
# File 'lib/ebngen/translate.rb', line 76 def translate translate_project() return [@data_out, @data_in_component, @data_in] #puts @data_out.to_yaml end |