Module: ObservationsHelper

Defined in:
app/helpers/observations_helper.rb

Instance Method Summary collapse

Instance Method Details

#degrees_and_cardinal(degrees) ⇒ String

Used to display both the cardinal (general compass direction) and degrees from north

Examples:

degrees_and_cardinal(90)

=>  "E (90°)"

Parameters:

  • degrees (FixNum)

Returns:

  • (String)

8
9
10
11
12
# File 'app/helpers/observations_helper.rb', line 8

def degrees_and_cardinal(degrees)
  if degrees
    "%s (%d°)" % [Geocoder::Calculations.compass_point(degrees), degrees]
  end
end

#speed_min_max(observation) ⇒ String

Makes a formatted string for displaying wind speed.

Examples:

speed_min_max( Observation.new(speed: 5, min: 2, max: 7) )

=> "5 (2-7)m/s"

Parameters:

  • []

Returns:

  • (String)

19
20
21
22
23
24
25
26
# File 'app/helpers/observations_helper.rb', line 19

def speed_min_max(observation)
  unless observation.is_a? Hash
    observation = HashWithIndifferentAccess.new(observation.attributes)
  end
  if observation
    "%{speed} (%{min_wind_speed}-%{max_wind_speed})m/s" % observation
  end
end

#time_date_hours_seconds(time) ⇒ String

TODO:

FIX - this does not properly handle timezones

Display a time and the date unless the time is during the current day.

Parameters:

  • time (DateTime|Time|TimeWithZone)

Returns:

  • (String)

40
41
42
# File 'app/helpers/observations_helper.rb', line 40

def time_date_hours_seconds(time)
  time.today? ? time_in_24h(time) : time.strftime("%m/%d %H:%M")
end

#time_in_24h(time) ⇒ String

TODO:

FIX - this does not properly handle timezones

Display a time in 24h format.

Parameters:

  • time (DateTime|Time|TimeWithZone)

Returns:

  • (String)

32
33
34
# File 'app/helpers/observations_helper.rb', line 32

def time_in_24h(time)
  time.strftime("%H:%M")
end