Sha256: 5a2edb8b900f354e3ed64478b6dad781284b44f0ec3586360c44a3cd2cdc0225

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

require 'time'
module Rack::App::Utils::Parser
  extend(self)

  require 'rack/app/utils/parser/custom'
  require 'rack/app/utils/parser/string'
  require 'rack/app/utils/parser/boolean'
  require 'rack/app/utils/parser/float'
  require 'rack/app/utils/parser/integer'
  require 'rack/app/utils/parser/numeric'

  def parse(type, str)
    string = str.to_s
    parser = get_parser(type)
    return unless parser.validate(string)
    parser.parse(string)
  end

  protected

  def get_parser(type)
    case true
    when [::String, :string].include?(type)
      self::String.new
    when [::TrueClass, ::FalseClass, :boolean].include?(type)
      self::Boolean.new
    when type == :date
      self::Custom.new(::Date)
    when type == :time
      self::Custom.new(::Time)
    when [:date_time, :datetime].include?(type)
      self::Custom.new(::DateTime)
    when [::Integer, :integer].include?(type)
      self::Integer.new
    when [::Float, :float].include?(type)
      self::Float.new
    when [::Numeric, :numeric].include?(type)
      self::Numeric.new
    else
      self::Custom.new(type)
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
rack-app-11.0.2 lib/rack/app/utils/parser.rb
rack-app-11.0.1 lib/rack/app/utils/parser.rb
rack-app-11.0.0 lib/rack/app/utils/parser.rb
rack-app-10.0.0 lib/rack/app/utils/parser.rb
rack-app-9.0.0 lib/rack/app/utils/parser.rb
rack-app-8.1.0 lib/rack/app/utils/parser.rb
rack-app-8.0.1 lib/rack/app/utils/parser.rb
rack-app-8.0.0 lib/rack/app/utils/parser.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/utils/parser.rb
rack-app-7.7.0 lib/rack/app/utils/parser.rb
rack-app-7.6.5 lib/rack/app/utils/parser.rb
rack-app-7.6.4 lib/rack/app/utils/parser.rb
rack-app-7.6.3 lib/rack/app/utils/parser.rb
rack-app-7.6.2 lib/rack/app/utils/parser.rb
rack-app-7.6.1 lib/rack/app/utils/parser.rb
rack-app-7.6.0 lib/rack/app/utils/parser.rb
rack-app-7.5.2 lib/rack/app/utils/parser.rb
rack-app-7.5.1 lib/rack/app/utils/parser.rb
rack-app-7.5.0 lib/rack/app/utils/parser.rb
rack-app-7.4.0 lib/rack/app/utils/parser.rb