32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/osgb/has_gridref.rb', line 32
def convert_between_gridref_and_latlng
options = self.class.osgb_options
cols = self.class.column_names
if cols.include?(options[:lat]) && cols.include?(options[:lng]) && cols.include?(options[:gridref])
if send("#{options[:gridref]}_changed?") || !send("#{options[:lat]}?") || !send("#{options[:lng]}?")
point = gridref.to_latlng
send("#{options[:lat]}=", point.lat)
send("#{options[:lng]}=", point.lng)
elsif send("#{options[:lat]}_changed?") || send("#{options[:lng]}_changed?") || !send("#{options[:gridref]}?")
send("#{options[:gridref]}=", Osgb::Gridref.from(send(options[:lat]), send(options[:lng])))
end
else
raise Osgb::OsgbConfigurationError "OSGB was expecting to see #{options[:lat]}, #{options[:lng]} and #{options[:gridref]} columns."
end
end
|