presently I am using : zl = 13-[2,5,10,15,25].index(last_city_km)
when last_city_km is one of these fixed values to get a zoom level,
now, there is a change in customer requirement, last_city_km is
calculated, so
last_city_km can be an integer value between 0 and 25,
and I would like to calculate (DRY) the zoom level such as :
last_city_km can be 0
if last_city_km <= 2 then zl = 13
if 2 < last_city_km <= 5 then zl = 12
if 5 < last_city_km <= 10 then zl = 12
if 10 < last_city_km <= 15 then zl = 12
if 15 < last_city_km <= 25 then zl = 12
if 25 < last_city_km… cannot !
thanks for
On 2/2/07, Josselin [email protected] wrote:
if 2 < last_city_km <= 5 then zl = 12
if 5 < last_city_km <= 10 then zl = 11
if 10 < last_city_km <= 15 then zl = 10
if 15 < last_city_km <= 25 then zl = 9
if 25 < last_city_km… cannot !
thanks for
13 - [2,5,10,15,25].select{|i| last_city_km <= i}.size - 1
14 - [2,5,10,15,25].select{|i| last_city_km <= i}.size
On Fri, 2 Feb 2007, Josselin wrote:
if 2 < last_city_km <= 5 then zl = 12
if 5 < last_city_km <= 10 then zl = 12
if 10 < last_city_km <= 15 then zl = 12
if 15 < last_city_km <= 25 then zl = 12
if 25 < last_city_km… cannot !
thanks for
if you think you might end up adding even more logic you might consider
something like:
harp: ~> cat a.rb
require ‘yaml’
[2, 5, 10, 15, 25].each do |last_city_km|
base = 13
zl = base - case last_city_km
when 0 … 2; 0
when 2 … 5; 1
when 5 … 10; 2
when 10 … 15; 3
when 15 … 25; 4
else; raise RangeError, last_city_km.inspect
end
y last_city_km => zl
end
harp: ~> ruby a.rb
2: 13
5: 12
10: 11
15: 10
25: 9
regards.
-a