Module: AprsParser::TypeSafety
- Included in:
- Structs::Package, Structs::Telemetry, Structs::WxReport
- Defined in:
- lib/aprs_parser/type_safety.rb
Overview
Checks all values coming in and makes sure they are of an instance of the correct #type_class.
Instance Method Summary collapse
-
#to_native(value, ctx) ⇒ Object
Convert given value to native value, with type checking.
-
#type_class ⇒ Object
Retrieve the type that all objects going into to_native must be of.
Instance Method Details
#to_native(value, ctx) ⇒ Object
Note:
Calls super-implementation if type is safe.
Convert given value to native value, with type checking.
12 13 14 15 16 17 18 |
# File 'lib/aprs_parser/type_safety.rb', line 12 def to_native(value, ctx) if value.is_a?(type_class) super else fail TypeError, "expected a kind of #{name}, was #{value.class}" end end |
#type_class ⇒ Object
Retrieve the type that all objects going into to_native must be of.
23 24 25 |
# File 'lib/aprs_parser/type_safety.rb', line 23 def type_class self end |