Sha256: 4b3f7b6778e0e7079acee4c0739bd9a95065cc61fe351720e2880a73c79011d3
Contents?: true
Size: 834 Bytes
Versions: 10
Compression:
Stored size: 834 Bytes
Contents
module DropboxApi::Metadata class Field def initialize(type, options = []) @type = type @options = options end def cast(object) if object.nil? raise ArgumentError unless @options.include? :optional nil else force_cast object end end def force_cast(object) if @type == String object.to_s elsif @type == Time Time.parse(object) elsif @type == Integer object.to_i elsif @type == Float object.to_f elsif @type == Symbol object[".tag"].to_sym elsif @type == :boolean object.to_s == "true" elsif @type.ancestors.include? DropboxApi::Metadata::Base @type.new(object) else raise NotImplementedError, "Can't cast `#{@type}`" end end end end
Version data entries
10 entries across 10 versions & 1 rubygems