def self.option(ftype,name,type,num,opts=nil)
case type
when :enum
if opts.is_a? Array then
opts=Hash[opts.each_with_index.to_a]
elsif not opts.is_a? Hash then
raise TypeError, "Ethon::Curls::Options #{ftype} #{name} Expected opts to be an Array or a Hash."
end
when :bitmask
if opts.is_a? Array then
if opts.last.is_a? Hash then
hopts=opts.pop
else
hopts={}
end
opts.each_with_index do |v,i|
next if v.nil?
if i==0 then
hopts[v]=0
else
hopts[v]=1<<(i-1)
end
end
opts=hopts
elsif not opts.is_a? Hash then
raise TypeError, "Ethon::Curls::Options #{ftype} #{name} Expected opts to be an Array or a Hash."
end
opts[:all]=-1 unless opts.include? :all
opts.each do |k,v|
if v.is_a? Array then
opts[k]=v.map { |b| opts[b] }.inject :|
end
end
when :buffer
raise TypeError, "Ethon::Curls::Options #{ftype} #{name} Expected opts to be an Array or a Hash." unless opts.is_a? Integer
else
raise ArgumentError, "Ethon::Curls::Options #{ftype} #{name} Expected no opts." unless opts.nil?
end
opthash=const_get(FOPTION_STRINGS[ftype])
opthash[name] = { :type => type,
:opt => OPTION_TYPE_BASE[OPTION_TYPE_MAP[type]] + num,
:opts => opts }
end