Module: Atmospheric::Export::AltitudeConvertableModel
Class Method Summary
collapse
Instance Method Summary
collapse
-
#realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced) ⇒ Object
-
#realize_values_from_geopotential(gp_h_m, precision:) ⇒ Object
-
#set_altitude(value:, type: :geometric, unit: :meters, precision: :reduced) ⇒ Object
-
#set_geometric_altitude(h, unit: :meters, precision: :reduced) ⇒ Object
-
#set_geopotential_altitude(h, unit: :meters, precision: :reduced) ⇒ Object
Methods included from Utils
#ft_to_m, #m_to_ft, #round_to_sig_figs, #values_in_m_ft
Class Method Details
.included(base) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/atmospheric/export/altitude_convertable_model.rb', line 12
def self.included(base)
base.class_eval do
attribute :geometric_altitude_m, UnitValueInteger
attribute :geometric_altitude_ft, UnitValueInteger
attribute :geopotential_altitude_m, UnitValueInteger
attribute :geopotential_altitude_ft, UnitValueInteger
end
end
|
Instance Method Details
#realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/atmospheric/export/altitude_convertable_model.rb', line 56
def realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced)
self.geometric_altitude_m = UnitValueInteger.new(
value: precision == :reduced ? hgmm.round : hgmm,
unitsml: "m"
)
self.geometric_altitude_ft = UnitValueInteger.new(
value: precision == :reduced ? hgmf.round : hgmf,
unitsml: "ft"
)
self.geopotential_altitude_m = UnitValueInteger.new(
value: precision == :reduced ? hgpm.round : hgpm,
unitsml: "m"
)
self.geopotential_altitude_ft = UnitValueInteger.new(
value: precision == :reduced ? hgpf.round : hgpf,
unitsml: "ft"
)
end
|
#realize_values_from_geopotential(gp_h_m, precision:) ⇒ Object
78
79
80
81
|
# File 'lib/atmospheric/export/altitude_convertable_model.rb', line 78
def realize_values_from_geopotential(gp_h_m, precision:)
raise NotImplementedError,
"realize_values_from_geopotential method must be implemented in the including class"
end
|
#set_altitude(value:, type: :geometric, unit: :meters, precision: :reduced) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/atmospheric/export/altitude_convertable_model.rb', line 21
def set_altitude(value:, type: :geometric, unit: :meters,
precision: :reduced)
case type
when :geometric
set_geometric_altitude(value, unit: unit, precision: precision)
when :geopotential
set_geopotential_altitude(value, unit: unit, precision: precision)
else
raise ArgumentError,
"Invalid type: #{type}. Use :geometric or :geopotential."
end
self
end
|
#set_geometric_altitude(h, unit: :meters, precision: :reduced) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/atmospheric/export/altitude_convertable_model.rb', line 46
def set_geometric_altitude(h, unit: :meters, precision: :reduced)
hgmm, hgmf = values_in_m_ft(h, unit: unit)
hgpm = Isa::NormalPrecision.instance.geopotential_altitude_from_geometric(hgmm)
hgpf = m_to_ft(hgpm).round
realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced)
realize_values_from_geopotential(hgpm, precision: precision)
end
|
#set_geopotential_altitude(h, unit: :meters, precision: :reduced) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/atmospheric/export/altitude_convertable_model.rb', line 36
def set_geopotential_altitude(h, unit: :meters, precision: :reduced)
hgpm, hgpf = values_in_m_ft(h, unit: unit)
hgmm = Isa::NormalPrecision.instance.geometric_altitude_from_geopotential(hgpm)
hgmf = m_to_ft(hgmm).round
realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced)
realize_values_from_geopotential(hgpm, precision: precision)
end
|