Module: Atmospheris::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
8
9
10
11
12
13
|
# File 'lib/atmospheris/export/altitude_convertable_model.rb', line 8
def self.included(base)
base.class_eval do
attribute :geometric_altitudes, UnitValueInteger, collection: true
attribute :geopotential_altitudes, UnitValueInteger, collection: true
end
end
|
Instance Method Details
#realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/atmospheris/export/altitude_convertable_model.rb', line 50
def realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced)
self.geometric_altitudes = [
UnitValueInteger.new(
value: precision == :reduced ? hgmm.round : hgmm,
unitsml: "m"
),
UnitValueInteger.new(
value: precision == :reduced ? hgmf.round : hgmf,
unitsml: "ft"
)
]
self.geopotential_altitudes = [
UnitValueInteger.new(
value: precision == :reduced ? hgpm.round : hgpm,
unitsml: "m"
),
UnitValueInteger.new(
value: precision == :reduced ? hgpf.round : hgpf,
unitsml: "ft"
)
]
end
|
#realize_values_from_geopotential(gp_h_m, precision:) ⇒ Object
74
75
76
77
|
# File 'lib/atmospheris/export/altitude_convertable_model.rb', line 74
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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/atmospheris/export/altitude_convertable_model.rb', line 15
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
40
41
42
43
44
45
46
47
48
|
# File 'lib/atmospheris/export/altitude_convertable_model.rb', line 40
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
30
31
32
33
34
35
36
37
38
|
# File 'lib/atmospheris/export/altitude_convertable_model.rb', line 30
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
|