Module: ELA::Utils

Included in:
ELA
Defined in:
lib/ela/utils.rb

Instance Method Summary collapse

Instance Method Details

#labelsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ela/utils.rb', line 72

def labels
  preamble = <<EOF
  # PLEASE DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST AFTER THE NEXT APP UPDATE
  # Create a file `labels.overwrite.yml.txt` and place particular changes there. Example:
  #
  # airplaneInternalLoads:
  #   fuselage:
  #     shortTitle: FLL
  # mohrsCircle:
  #   shortTitle: Mohr's Circus

EOF
  preamble + yml_config(:labels)
end

#page_titleObject



122
123
124
125
126
127
128
129
# File 'lib/ela/utils.rb', line 122

def page_title
  global_settings_path = File.join(Dir.pwd, 'settings.yml')
  if File.exists?(global_settings_path)
    yml = YAML.load(File.read(global_settings_path))
    yml_title = yml['page'].andand['title']
  end
  yml_title or 'E-Learning Apps'
end

#settingsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ela/utils.rb', line 21

def settings
  preamble = <<EOF
  # PLEASE DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST AFTER THE NEXT UPDATE
  # Create a file `settings.overwrite.yml.txt` and place particular changes there. Example:
  #
  # directOperatingCosts:
  #   airplanes:
  #     A 300 B4-200:
  #       speed: 855
  #     ILR Super Aircraft:
  #       maxTakeOffMass: 165000
  #       maxFuelMass: 59646
  #       operationEmptyMass: 80640
  #       maxPayload: 45360
  #       maxRange: 8412
  #       speed: 2300
  #       engineCount: 6
  #       slst: 233
  #       engine: 6 x 233kN CF6-50C2
  #       reference: ILR12345
  # beamSectionProperties:
  #   zProfile:
  #     defaults:
  #       h: 12.5
  #
  # Structure:
  #
  # {appName}:
  #   curves:
  #     {curveName}:
  #       group: {groupName} # Translation in labels.yml.txt file at {appName} -> listAnchors -> {groupName} -> label
  #       selected: (true|false)
  #   defaults:
  #     {parameterName}: {parameterDefaultValue}
  #   formFields:
  #     {fieldName}:
  #       range: [{fieldFrom}, {fieldTo}] # including boundary values
  #       stepSize: {fieldStepSize}
  #       group: {fieldGroupName} # Translated to "Field Group Name"
  #       precision: {fieldPrecision} # Decimal places for computed fields
  #   {subappPath}: # subapp settings are more specific and therfore supercede settings from parent layers
  #     curves:
  #       {curveName}:
  #         selected: (true|false)
  #
  # In this file, all curves, parameters and formFields are present even if they have no dedicated settings.

EOF
  preamble + yml_config(:settings)
end

#write_labels_yml(path) ⇒ Object



10
11
12
# File 'lib/ela/utils.rb', line 10

def write_labels_yml(path)
  File.write(path, labels)
end

#write_settings_yml(path) ⇒ Object



6
7
8
# File 'lib/ela/utils.rb', line 6

def write_settings_yml(path)
  File.write(path, settings)
end

#write_yml(name, path) ⇒ Object



14
15
16
17
18
19
# File 'lib/ela/utils.rb', line 14

def write_yml(name, path)
  case name
  when :settings then write_settings_yml(path)
  when :labels then write_labels_yml(path)
  end
end

#yml_config(name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/ela/utils.rb', line 87

def yml_config(name)
  global_yml_path = File.join(Dir.pwd, "#{name}.yml")
  s = ''
  if File.exists?(global_yml_path)
    s += File.read(global_yml_path)
  end

  apps = ''
  app_settings = ''
  apps_path = File.join(Dir.pwd, 'apps')

  Dir.new(apps_path).each do |entry|
    next if ['.', '..'].include?(entry)

    entry_path = File.join(apps_path, entry)
    next unless File.directory?(entry_path)

    apps += "  - #{entry}\n"
    app_settings += "#{entry}:\n"

    app_yml_path = File.join(entry_path, "#{name}.yml")
    if File.exists?(app_yml_path)
      File.readlines(app_yml_path).each do |line|
        app_settings += "  #{line}"
      end
    end
  end

  if name == :settings
    s += "apps:\n#{apps}"
  end

  s + app_settings
end