Module: LoraRuby::Types
- Defined in:
- lib/lora_ruby/types.rb
Overview
Shared value model — aligned with the ‘LoraValue` contract used by `lora-node`, `lora-wasm`, and `lora-python`.
-
Scalars pass through as Ruby natives (‘nil`, `true`, `false`, `Integer`, `Float`, `String`).
-
Lists and maps come back as ‘Array` / `Hash` (string keys).
-
Graph, temporal, and spatial values come back as plain ‘Hash`es with a `“kind”` discriminator.
If you want to narrow a value explicitly, use the ‘node?` / `point?` / `temporal?` helpers below.
Constant Summary collapse
- SRID_CARTESIAN_2D =
7203- SRID_CARTESIAN_3D =
9157- SRID_WGS84_2D =
4326- SRID_WGS84_3D =
4979- CRS_CARTESIAN_2D =
"cartesian"- CRS_CARTESIAN_3D =
"cartesian-3D"- CRS_WGS84_2D =
"WGS-84-2D"- CRS_WGS84_3D =
"WGS-84-3D"- TEMPORAL_KINDS =
%w[date time localtime datetime localdatetime duration].freeze
- VECTOR_COORD_TYPES =
%w[FLOAT64 FLOAT32 INTEGER INTEGER32 INTEGER16 INTEGER8].freeze
Class Method Summary collapse
-
.cartesian(x, y) ⇒ Object
—————————————————————— Spatial constructors — mirrors lora_python.cartesian / wgs84.
- .cartesian_3d(x, y, z) ⇒ Object
-
.date(iso) ⇒ Object
—————————————————————— Temporal constructors — ISO-8601 tagged Hashes.
- .datetime(iso) ⇒ Object
- .duration(iso) ⇒ Object
- .kind_of(hash) ⇒ Object
- .localdatetime(iso) ⇒ Object
- .localtime(iso) ⇒ Object
-
.node?(v) ⇒ Boolean
—————————————————————— Guards — duck-typed narrowing helpers.
- .path?(v) ⇒ Boolean
- .point?(v) ⇒ Boolean
- .relationship?(v) ⇒ Boolean
- .tagged?(v, expected) ⇒ Boolean
- .temporal?(v) ⇒ Boolean
- .time(iso) ⇒ Object
-
.vector(values, dimension, coordinate_type) ⇒ Object
—————————————————————— Vector constructor — returns the canonical tagged Hash that the engine accepts as a VECTOR parameter and emits on return.
- .vector?(v) ⇒ Boolean
- .wgs84(longitude, latitude) ⇒ Object
- .wgs84_3d(longitude, latitude, height) ⇒ Object
Class Method Details
.cartesian(x, y) ⇒ Object
Spatial constructors — mirrors lora_python.cartesian / wgs84. ‘cartesian(1, 2)` returns a 2D cartesian point; use `cartesian_3d` for the 3D variant. WGS-84 variants carry `longitude` / `latitude` aliases alongside `x` / `y` so result-side consumers can read either without conversion.
67 68 69 70 71 72 73 74 75 |
# File 'lib/lora_ruby/types.rb', line 67 def cartesian(x, y) { "kind" => "point", "srid" => SRID_CARTESIAN_2D, "crs" => CRS_CARTESIAN_2D, "x" => x.to_f, "y" => y.to_f, } end |
.cartesian_3d(x, y, z) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/lora_ruby/types.rb', line 77 def cartesian_3d(x, y, z) { "kind" => "point", "srid" => SRID_CARTESIAN_3D, "crs" => CRS_CARTESIAN_3D, "x" => x.to_f, "y" => y.to_f, "z" => z.to_f, } end |
.date(iso) ⇒ Object
Temporal constructors — ISO-8601 tagged Hashes. The native extension normalises + validates these on the way into the engine; invalid ISO strings raise ‘LoraRuby::InvalidParamsError`.
38 |
# File 'lib/lora_ruby/types.rb', line 38 def date(iso) = { "kind" => "date", "iso" => iso } |
.datetime(iso) ⇒ Object
41 |
# File 'lib/lora_ruby/types.rb', line 41 def datetime(iso) = { "kind" => "datetime", "iso" => iso } |
.duration(iso) ⇒ Object
43 |
# File 'lib/lora_ruby/types.rb', line 43 def duration(iso) = { "kind" => "duration", "iso" => iso } |
.kind_of(hash) ⇒ Object
136 137 138 |
# File 'lib/lora_ruby/types.rb', line 136 def kind_of(hash) hash["kind"] || hash[:kind] end |
.localdatetime(iso) ⇒ Object
42 |
# File 'lib/lora_ruby/types.rb', line 42 def localdatetime(iso) = { "kind" => "localdatetime", "iso" => iso } |
.localtime(iso) ⇒ Object
40 |
# File 'lib/lora_ruby/types.rb', line 40 def localtime(iso) = { "kind" => "localtime", "iso" => iso } |
.node?(v) ⇒ Boolean
Guards — duck-typed narrowing helpers. Accept symbol-keyed and string-keyed Hashes because that’s what callers might build up manually (the native extension always emits string keys).
120 |
# File 'lib/lora_ruby/types.rb', line 120 def node?(v) = tagged?(v, "node") |
.path?(v) ⇒ Boolean
122 |
# File 'lib/lora_ruby/types.rb', line 122 def path?(v) = tagged?(v, "path") |
.point?(v) ⇒ Boolean
123 |
# File 'lib/lora_ruby/types.rb', line 123 def point?(v) = tagged?(v, "point") |
.relationship?(v) ⇒ Boolean
121 |
# File 'lib/lora_ruby/types.rb', line 121 def relationship?(v) = tagged?(v, "relationship") |
.tagged?(v, expected) ⇒ Boolean
131 132 133 134 |
# File 'lib/lora_ruby/types.rb', line 131 def tagged?(v, expected) return false unless v.is_a?(Hash) kind_of(v) == expected end |
.temporal?(v) ⇒ Boolean
126 127 128 129 |
# File 'lib/lora_ruby/types.rb', line 126 def temporal?(v) return false unless v.is_a?(Hash) TEMPORAL_KINDS.include?(kind_of(v)) end |
.time(iso) ⇒ Object
39 |
# File 'lib/lora_ruby/types.rb', line 39 def time(iso) = { "kind" => "time", "iso" => iso } |
.vector(values, dimension, coordinate_type) ⇒ Object
Vector constructor — returns the canonical tagged Hash that the engine accepts as a VECTOR parameter and emits on return.
50 51 52 53 54 55 56 57 |
# File 'lib/lora_ruby/types.rb', line 50 def vector(values, dimension, coordinate_type) { "kind" => "vector", "dimension" => dimension, "coordinateType" => coordinate_type.to_s, "values" => values.dup, } end |
.vector?(v) ⇒ Boolean
124 |
# File 'lib/lora_ruby/types.rb', line 124 def vector?(v) = tagged?(v, "vector") |
.wgs84(longitude, latitude) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/lora_ruby/types.rb', line 88 def wgs84(longitude, latitude) { "kind" => "point", "srid" => SRID_WGS84_2D, "crs" => CRS_WGS84_2D, "x" => longitude.to_f, "y" => latitude.to_f, "longitude" => longitude.to_f, "latitude" => latitude.to_f, } end |
.wgs84_3d(longitude, latitude, height) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/lora_ruby/types.rb', line 100 def wgs84_3d(longitude, latitude, height) { "kind" => "point", "srid" => SRID_WGS84_3D, "crs" => CRS_WGS84_3D, "x" => longitude.to_f, "y" => latitude.to_f, "z" => height.to_f, "longitude" => longitude.to_f, "latitude" => latitude.to_f, "height" => height.to_f, } end |