Top Level Namespace
Defined Under Namespace
Modules: I18N, Pema, Primate, PrimateInternal, Response, Route, Session Classes: Multipart, Request, RequestBag, RequestBody, SessionInstance
Instance Method Summary collapse
Instance Method Details
#type(value, helpers) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/primate/type.rb', line 5 def type(value, helpers) type = helpers.type(value).to_s if type == 'integer' return value.to_i end if type == 'float' return value.to_f end if type == 'boolean' return value == JS::True end if type == 'string' return value.to_s end if type == 'nil' return nil end if type == 'array' as_array = JS.global[:Array].from(value) return Array.new(as_array[:length].to_i) { type(as_array[_1], helpers) } end if type == 'object' as_entries = JS.global[:Object].entries(value) return Hash[Array.new(as_entries[:length].to_i) {[ as_entries[_1][0].to_s, type(as_entries[_1][1], helpers) ]}] end value end |