Module: SchemaGraphy::SGYML
- Defined in:
- lib/schemagraphy/sgyml.rb
Overview
Provides SGYML (SchemaGraphy YAML-based Modeling Language) type classification. This is the canonical source for SGYML data types used across DocOps Lab tooling.
Type strings are in “Kind:Class” form, e.g. “Scalar:String”, “Compound:ArrayList”, “Null:nil”. Downstream gems (AsciiSourcerer, ReleaseHx, etc.) that render SGYML templates should obtain this classification via SchemaGraphy rather than re-implementing it.
Class Method Summary collapse
-
.classify(input) ⇒ String
Classifies a Ruby value by its SGYML type.
- .classify_array(input) ⇒ Object
- .classify_hash(input) ⇒ Object
Class Method Details
.classify(input) ⇒ String
Classifies a Ruby value by its SGYML type.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/schemagraphy/sgyml.rb', line 17 def classify input if input.nil? 'Null:nil' elsif input.is_a?(Array) classify_array(input) elsif input.is_a?(Hash) classify_hash(input) elsif input.is_a?(String) 'Scalar:String' elsif input.is_a?(Integer) 'Scalar:Number' elsif input.is_a?(Float) 'Scalar:Float' elsif input.is_a?(Time) 'Scalar:DateTime' elsif input.is_a?(TrueClass) || input.is_a?(FalseClass) 'Scalar:Boolean' else 'unknown:unknown' end end |
.classify_array(input) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/schemagraphy/sgyml.rb', line 39 def classify_array input if input.all? do |i| i.is_a?(Integer) || i.is_a?(Float) || i.is_a?(String) || i.is_a?(TrueClass) || i.is_a?(FalseClass) end 'Compound:ArrayList' elsif input.all? { |i| i.is_a?(Hash) && i.keys.length >= 2 } 'Compound:ArrayTable' else 'Compound:Array' end end |
.classify_hash(input) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/schemagraphy/sgyml.rb', line 51 def classify_hash input if input.values.all? { |v| v.is_a?(Hash) && v.keys.length >= 2 } 'Compound:MapTable' else 'Compound:Map' end end |