Sha256: 27e0aa80cf6c9367744af602848740939f05ae022d88a139f0b7dd317ecf3c20
Contents?: true
Size: 1.71 KB
Versions: 2
Compression:
Stored size: 1.71 KB
Contents
# encoding: utf-8 require 'pathname' require 'necromancer' require_relative 'converter_dsl' module TTY class Prompt module Converters extend ConverterDSL # Delegate Necromancer errors # # @api private def self.on_error if block_given? yield else raise ArgumentError, 'You need to provide a block argument.' end rescue Necromancer::ConversionTypeError => e raise ConversionError, e.message end converter(:bool) do |input| on_error { Necromancer.convert(input).to(:boolean, strict: true) } end converter(:string) do |input| String(input).chomp end converter(:symbol) do |input| input.to_sym end converter(:date) do |input| on_error { Necromancer.convert(input).to(:date, strict: true) } end converter(:datetime) do |input| on_error { Necromancer.convert(input).to(:datetime, strict: true) } end converter(:int) do |input| on_error { Necromancer.convert(input).to(:integer, strict: true) } end converter(:float) do |input| on_error { Necromancer.convert(input).to(:float, strict: true) } end converter(:range) do |input| on_error { Necromancer.convert(input).to(:range, strict: true) } end converter(:regexp) do |input| Regexp.new(input) end converter(:file) do |input| ::File.open(::File.join(Dir.pwd, input)) end converter(:path) do |input| Pathname.new(::File.join(Dir.pwd, input)) end converter(:char) do |input| String(input).chars.to_a[0] end end # Converters end # Prompt end # TTY
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tty-prompt-0.15.0 | lib/tty/prompt/converters.rb |
tty-prompt-0.14.0 | lib/tty/prompt/converters.rb |