Sha256: d3578ca57dd5ef9dc88de4fb5306aad2f6d1d492b19ccf9fbc88fe1f0aaf422d

Contents?: true

Size: 515 Bytes

Versions: 1

Compression:

Stored size: 515 Bytes

Contents

class JsonParser::Wrapper
  include OptionsParser
  include TypeCast

  delegate :clazz, :type, to: :options_object

  def initialize(options = {})
    @options = options
  end

  def wrap(value)
    return value.map { |v| wrap v } if value.is_a?(Array)

    value = cast(value) if has_type? && !value.nil?
    return if value.nil?

    value = clazz.new(value) if clazz
    value
  end

  private

  def has_type?
    type.present? && type != :none
  end

  def cast(value)
    send("to_#{type}", value)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
json_parser-1.0.0 lib/json_parser/wrapper.rb