-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathski_report.rb
44 lines (38 loc) · 1.09 KB
/
ski_report.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'rubygems'
require 'open-uri'
require 'xmlsimple'
module SkiReport
def self.fetch(state)
state.downcase!.gsub!(/[ ]/,'-')
url = "http://www.onthesnow.com/#{state}/snow.rss"
src = ""; file = open(url) { |f| f.each_line { |line| src += line.gsub(/ots:/, '') }}
feed = XmlSimple.xml_in(src)['channel'][0]['item']
SkiReport::Report.new feed
end
class Report
def initialize(feed)
@feed = feed
end
def resorts
@feed.collect do |item|
SkiReport::Resort.new({
:name => item['title'],
:updated => item['pubDate'],
:status => item['open_staus'],
:conditions => item['surface_condition'],
:base => { :depth => item['base_depth'], :metric => item['base_depth_metric'] },
:snowfall => { :amount => item['snowfall_48hr'], :metric => item['snowfall_48hr_metric'] }})
end
end
end
class Resort
def initialize(attributes)
@attributes = attributes
end
['name','updated','status','base','snowfall','conditions'].each do |arg|
send :define_method, arg.to_sym do
@attributes[arg] || @attributes[arg.to_sym]
end
end
end
end