def is_translated?
if !params[:lang].blank? and params[:lang].eq?('en')
return true
end
if !cookies[:lang].blank? and cookies[:lang].eq?('en')
return true
end
if !session[:lang].blank? and session[:lang].eq?('en')
return true
end
if !session[:locale].blank? and session[:locale].eq?('en')
return true
end
if !params[:locale].blank? and params[:locale].eq?('en')
return true
end
end
Refactorings
No refactoring yet !
op
August 9, 2010, August 09, 2010 11:22, permalink
You could make it a lot shorter at least..
def is_translated
[params, cookies, session].each do |store|
return true if !store[:lang].blank? && store[:lang].eq?('en')
end
[session, params].each do |store|
return true if !store[:locale].blank? && store[:locale].eq?('en')
end
false
end
Rick DeNatale
August 9, 2010, August 09, 2010 14:03, permalink
How about
def is_translated (params[:lang] || cookies[:lang] || session[:lang] || session[:locale] || params[:locale]) == 'en' end
corroded
August 9, 2010, August 09, 2010 14:14, permalink
going with op's code i editted the method name + added andand to make it shorter still.
def is_english?
[params, cookies, session].each do |store|
return (store[:lang].andand.to_s == "en" || store[:locale].andand.to_s == "eng")
end
false
end
there are too many if then statements and and clauses. is the method trying to do too much?