Skip to content

Instantly share code, notes, and snippets.

@tanordheim
Created January 20, 2012 22:11
Show Gist options
  • Save tanordheim/1649890 to your computer and use it in GitHub Desktop.
Save tanordheim/1649890 to your computer and use it in GitHub Desktop.
Yr Dataa Source Mapping
> ds = DataSources::XML.new(:url => 'http://www.yr.no/place/Norway/S%C3%B8r-Tr%C3%B8ndelag/Trondheim/Trondheim/varsel.xml')
> ds.mappings.build(:name => 'copyright', :input => 'weatherdata/credit/link/@text')
> ds.mappings.build(:name => 'location', :input => 'weatherdata/forecast/text/location/@name')
> ds.mappings.build(:name => 'forecast_period', :input => 'weatherdata/forecast/text/location/time/title/text')
> ds.mappings.build(:name => 'forecast', :input => 'weatherdata/forecast/text/location/time/body/text')
> ds.mappings.build(:name => 'weather_symbol_id', :input => 'weatherdata/forecast/tabular/time/symbol/@number')
> ds.mappings.build(:name => 'weather_symbol_name', :input => 'weatherdata/forecast/tabular/time/symbol/@name')
> ds.mappings.build(:name => 'wind_speed_mps', :input => 'weatherdata/forecast/tabular/time/windSpeed/@mps')
> ds.mappings.build(:name => 'wind_speed_name', :input => 'weatherdata/forecast/tabular/time/windSpeed/@name')
> ds.mappings.build(:name => 'wind_direction_code', :input => 'weatherdata/forecast/tabular/time/windDirection/@code')
> ds.mappings.build(:name => 'wind_direction_name', :input => 'weatherdata/forecast/tabular/time/windDirection/@name')
> ds.mappings.build(:name => 'temperature', :input => 'weatherdata/forecast/tabular/time/temperature/@value')
> ds.transformed
[{"copyright"=>
"Weather forecast from yr.no, delivered by the Norwegian Meteorological Institute and the NRK",
"location"=>"Trondheim",
"forecast_period"=>"Friday and Saturday",
"forecast"=>
"<strong>Sør-Trøndelag:</strong> I kveld dreining til sørøstlig bris, i natt frisk bris 10 m/s. Etter hvert delvis skyet, oppholdsvær. Lørdag morgen økning til sørøstlig stiv kuling 15 utsatte steder, på kysten sterk kuling 20. Delvis skyet, oppholdsvær.",
"weather_symbol_id"=>"3",
"weather_symbol_name"=>"Partly cloudy",
"wind_speed_mps"=>"2.5",
"wind_speed_name"=>"Light breeze",
"wind_direction_code"=>"SSE",
"wind_direction_name"=>"South-southeast",
"temperature"=>"-1"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment