Class: Mayak::Csv::Decoder::HashDecoder

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Generic, T::Sig
Includes:
Mayak::Csv::Decoder
Defined in:
lib/mayak/csv/decoder.rb

Constant Summary collapse

Value =
type_member {{ fixed: T::Hash[String, T.nilable(String)] }}

Instance Method Summary collapse

Methods included from Mayak::Csv::Decoder

hash_decoder, hash_decoder_strict, #map, #map_try

Instance Method Details

#decode(csv) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/mayak/csv/decoder.rb', line 75

def decode(csv)
  csv_string = begin
    case csv
    when String then csv
    else csv.to_a.join("\n")
    end
  end
  Mayak::Monads::Try::Success.new(CSV.parse(csv_string, headers: :first_row, col_sep: separator).map(&:to_h))
end