Created
June 27, 2016 12:52
-
-
Save eidge/86a1a5397132b2aed91ab9e54bc6318b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Weather.NOAA.Forecast.Params do | |
@moduledoc """ | |
Defines a struct to map NOAA's forecast params and fuctions to build and | |
handle them. | |
""" | |
defstruct model_name: :gfs_1p00, date: nil, cycle: 0, hour_delta: 0, bounding_box: nil | |
@type t :: %__MODULE__{ | |
model_name: String.t, | |
date: Timex.Date.t, | |
cycle: non_neg_integer, | |
hour_delta: non_neg_integer, | |
bounding_box: %{ | |
top_latitude: float, | |
bottom_latitude: float, | |
left_longitude: float, | |
right_longitude: float | |
} | |
} | |
@doc """ | |
Builds a %Forecast.Params{} struct with defaults set. | |
Args: | |
- options - A keyword list that overrides the default params | |
Returns %Forecast.Params{} | |
## Example | |
iex> Weather.NOAA.Forecast.Params.new | |
%Weather.NOAA.Forecast.Params{ | |
model_name: :gfs_1p00, # 1 degree precision gfs model | |
date: Timex.Date.today, # Today | |
cycle: 0, # Forecast cycle | |
hour_delta: 0, # Same time as forecast cycle | |
bounding_box: %{ # Entire world | |
left_longitude: 0, | |
top_latitude: 90, | |
right_longitude: 360, | |
bottom_latitude: -90 | |
} | |
} | |
""" | |
def new(params \\ []) do | |
params_map = Map.new(params) | |
%__MODULE__{ | |
date: Timex.Date.today, | |
bounding_box: entire_globe_bounding_box | |
} |> Map.merge(params_map) | |
end | |
defp entire_globe_bounding_box do | |
%{ | |
left_longitude: 0, | |
top_latitude: 90, | |
right_longitude: 360, | |
bottom_latitude: -90 | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment