Sha256: e40044ba9c37664a62dd252aca21505c395c1d49837c93c0ee26c432ab10602c

Contents?: true

Size: 777 Bytes

Versions: 1

Compression:

Stored size: 777 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Standard
      class DateTime
        module Services
          class SafeParse
            include ConvenientService::Standard::Config

            attr_reader :string, :format

            def initialize(string:, format:)
              @string = string
              @format = format
            end

            def result
              success(date_time: ::DateTime.strptime(string, format))
            rescue ::Date::Error => exception
              failure(
                data: {exception: exception},
                message: "Failed to parse `DateTime` object from `#{string}` with `#{format}`"
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
convenient_service-0.13.0 lib/convenient_service/examples/standard/date_time/services/safe_parse.rb