Module: GeoTools::FormHelpers
- Defined in:
- lib/geo_tools/form_helpers.rb
Instance Method Summary collapse
-
#latitude_field(method, options = {}) ⇒ Object
Options: :latitude :degrees :symbol :minutes :symbol :decimal_minutes :symbol :maxlength.
- #longitude_field(method, options = {}) ⇒ Object
Instance Method Details
#latitude_field(method, options = {}) ⇒ Object
Options:
:latitude
:degrees
:symbol
:minutes
:symbol
:decimal_minutes
:symbol
:maxlength
Assumes the latitude field is called ‘latitude’.
The ‘method’ argument is for consistency with other field helpers. We don’t use it when using the normal Rails form builder.
1/100th of a minute of latitude (or equitorial longitude) is approximately 20m.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/geo_tools/form_helpers.rb', line 21 def latitude_field(method, = {}) opts = { :degrees => { :symbol => '°' }, :minutes => { :symbol => '.' }, :decimal_minutes => { :symbol => '′', :maxlength => 2 }, } = .delete :latitude opts.merge! if output = [] # Degrees width = 2 output << text_field("latitude_degrees", .merge(:maxlength => width, :value => "%0#{width}d" % (@object.send("latitude_degrees") || 0))) output << opts[:degrees][:symbol] # Minutes width = 2 output << text_field("latitude_minutes", .merge(:maxlength => width, :value => "%0#{width}d" % (@object.send("latitude_minutes") || 0))) output << opts[:minutes][:symbol] # Decimal minutes width = opts[:decimal_minutes][:maxlength] output << text_field("latitude_decimal_minutes", .merge(:maxlength => width, :value => @object.send("latitude_decimal_minutes_as_string").ljust(width, '0'))) output << opts[:decimal_minutes][:symbol] # Hemisphere. # Hmm, we pass the options in the html_options position. output << select("latitude_hemisphere", %w( N S ), {}, ) output.join "\n" end |
#longitude_field(method, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/geo_tools/form_helpers.rb', line 60 def longitude_field(method, = {}) opts = { :degrees => { :symbol => '°' }, :minutes => { :symbol => '.' }, :decimal_minutes => { :symbol => '′', :maxlength => 2 }, } = .delete :longitude opts.merge! if output = [] # Degrees width = 3 output << text_field("longitude_degrees", .merge(:maxlength => width, :value => "%0#{width}d" % (@object.send("longitude_degrees") || 0))) output << opts[:degrees][:symbol] # Minutes width = 2 output << text_field("longitude_minutes", .merge(:maxlength => width, :value => "%0#{width}d" % (@object.send("longitude_minutes") || 0))) output << opts[:minutes][:symbol] # Decimal minutes width = opts[:decimal_minutes][:maxlength] output << text_field("longitude_decimal_minutes", .merge(:maxlength => width, :value => @object.send("longitude_decimal_minutes_as_string").ljust(width, '0'))) output << opts[:decimal_minutes][:symbol] # Hemisphere. # Hmm, we pass the options in the html_options position. output << select("longitude_hemisphere", %w( E W ), {}, ) output.join "\n" end |