def self.match_types(accept_types, have_types)
if accept_types.nil? or accept_types == []
default = 1
else
default = 0
end
match_main = {}
match_sub = {}
accept_types.each { |main, sub, q|
if main == '*'
default = [default, q].max
next
elsif sub == '*'
match_main[main] = [match_main.fetch(main, 0), q].max
else
match_sub[[main, sub]] = [match_sub.fetch([main, sub], 0), q].max
end
}
accepted_list = []
order_maintainer = 0
have_types.each { |mtype|
main, sub = mtype.split('/', 2)
if match_sub.member?([main, sub])
q = match_sub[[main, sub]]
else
q = match_main.fetch(main, default)
end
if q != 0
accepted_list << [1 - q, order_maintainer, q, mtype]
order_maintainer += 1
end
}
accepted_list.sort!
return accepted_list.collect { |_, _, q, mtype| [mtype, q] }
end