Module: StationsHelper

Defined in:
app/helpers/stations_helper.rb

Instance Method Summary collapse

Instance Method Details

#clear_observations_button(station, options = {}) ⇒ String

Create link to clear observations for station

Parameters:

  • station (Station)
  • options (Hash) (defaults to: {})

Returns:

  • (String)

7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/stations_helper.rb', line 7

def clear_observations_button(station, options = {})
  options.merge!({
      text: "Clear all observations for this station?",
      data:  {
        confirm:   "Are you sure you want to delete all measues recorded by this station? This action cannot be undone!"
      },
      class: "tiny button alert",
      method:  :delete
  })
  link_to options[:text], station_observations_path(station), options
end

#readable_duration(duration) ⇒ String

Displays a duration as a digital timer format

Examples:

readable_duration(1.hours)

=> "01:30:00"

Parameters:

  • station (ActiveSupport::Duration)

Returns:

  • (String)

47
48
49
# File 'app/helpers/stations_helper.rb', line 47

def readable_duration(duration)
  Time.at(duration.to_i).utc.strftime("%H:%M:%S")
end

#station_coordinates(station) ⇒ String

TODO:

CLEANUP

Parameters:

Returns:

  • (String)

38
39
40
# File 'app/helpers/stations_helper.rb', line 38

def station_coordinates(station)
  sprintf('data-lat="%d" data-lng="%d"', station.latitude, station.longitude).html_safe
end

#station_header(station) ⇒ String

Examples:

when online

station_header(station)
=> "Test station"

when offline

station_header(station)
=> "Test station(<em>offline</em>)"

Parameters:

Returns:

  • (String)

27
28
29
30
31
32
33
# File 'app/helpers/stations_helper.rb', line 27

def station_header(station)
  if station.offline?
    ( station.name + "(#{content_tag(:em, 'offline')})" ).html_safe
  else
    station.name
  end
end