Module: Type

Defined in:
lib/arkana/models/type.rb

Overview

A namespace that defines language-agnostic variable types.

Constant Summary collapse

STRING =
:string
BOOLEAN =
:boolean
INTEGER =
:integer

Class Method Summary collapse

Class Method Details

.new(string_value:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/arkana/models/type.rb', line 9

def self.new(string_value:)
  case string_value
    when "true", "false"
      BOOLEAN
    when /^\d+$/
      # Handles cases like "0001" which should be interpreted as strings
      return STRING if string_value.to_i.to_s != string_value
      # Handle int overflow
      return STRING if string_value.to_i > (2**31) - 1
      INTEGER
    else
      STRING
  end
end