Sha256: ecae217c3532878bd6b6ec512cc5e6c8f11dddbe08e515ec95c5c90bbb9c21c2

Contents?: true

Size: 543 Bytes

Versions: 1

Compression:

Stored size: 543 Bytes

Contents

class JsonParser::Wrapper
  include ConcernBuilder::OptionsParser
  include JsonParser::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.1.0 lib/json_parser/wrapper.rb