Module: Simple::SQL::Helpers::Decoder
- Extended by:
- PgArrayParser, Decoder
- Included in:
- Decoder
- Defined in:
- lib/simple/sql/helpers/decoder.rb,
lib/simple/sql/helpers/decoder.rb
Overview
private
Defined Under Namespace
Modules: HStore Classes: HashRecord, MultiColumns, SingleColumn
Class Method Summary collapse
Instance Method Summary collapse
- #decode_time(s) ⇒ Object
-
#decode_value(type, s) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Style/MultipleComparison.
Class Method Details
.new(result, into:, column_info:) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/simple/sql/helpers/decoder.rb', line 77 def self.new(result, into:, column_info:) # rubocop:disable Lint/ElseLayout if into == Hash then HashRecord.new(column_info) elsif result.nfields == 1 then SingleColumn.new(column_info) else MultiColumns.new(column_info) end end |
Instance Method Details
#decode_time(s) ⇒ Object
40 41 42 43 44 |
# File 'lib/simple/sql/helpers/decoder.rb', line 40 def decode_time(s) return s if s.is_a?(Time) ::Time.parse(s) end |
#decode_value(type, s) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Style/MultipleComparison
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple/sql/helpers/decoder.rb', line 11 def decode_value(type, s) case type when :unknown then s when :"character varying" then s when :integer then Integer(s) when :bigint then Integer(s) when :numeric then Float(s) when :"double precision" then Float(s) when :'integer[]' then s.scan(/-?\d+/).map { |part| Integer(part) } when :"character varying[]" then parse_pg_array(s) when :"text[]" then parse_pg_array(s) when :"timestamp without time zone" then decode_time(s) when :"timestamp with time zone" then decode_time(s) when :hstore then HStore.parse(s) when :json then ::JSON.parse(s) when :jsonb then ::JSON.parse(s) when :boolean then s == "t" || s == true else # unknown value, we just return the string here. # STDERR.puts "unknown type: #{type.inspect}" s end end |