Class: OnTheSnow::State::State
- Inherits:
-
Object
- Object
- OnTheSnow::State::State
- Defined in:
- lib/onthesnow/state/state.rb
Instance Attribute Summary collapse
-
#region_name ⇒ Object
readonly
Returns the value of attribute region_name.
-
#state_name ⇒ Object
readonly
Returns the value of attribute state_name.
-
#state_rss ⇒ Object
readonly
Returns the value of attribute state_rss.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(state_name, region_name, state_rss) ⇒ State
constructor
A new instance of State.
- #to_hash ⇒ Object
Constructor Details
#initialize(state_name, region_name, state_rss) ⇒ State
Returns a new instance of State.
6 7 8 9 10 11 |
# File 'lib/onthesnow/state/state.rb', line 6 def initialize(state_name, region_name, state_rss) @state_name = state_name @region_name = region_name @state_rss = state_rss @api = OnTheSnow::API.instance end |
Instance Attribute Details
#region_name ⇒ Object (readonly)
Returns the value of attribute region_name.
4 5 6 |
# File 'lib/onthesnow/state/state.rb', line 4 def region_name @region_name end |
#state_name ⇒ Object (readonly)
Returns the value of attribute state_name.
4 5 6 |
# File 'lib/onthesnow/state/state.rb', line 4 def state_name @state_name end |
#state_rss ⇒ Object (readonly)
Returns the value of attribute state_rss.
4 5 6 |
# File 'lib/onthesnow/state/state.rb', line 4 def state_rss @state_rss end |
Class Method Details
.all ⇒ Object
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 |
# File 'lib/onthesnow/state/state.rb', line 13 def self.all if @states @states else @states = {} @api = OnTheSnow::API.instance @api.sitemap.css('#site_map_rss').each{|element| cols = [".colA",".colB"] @states_count = 0 cols.each do |col| region = element.css(col) states = region.css('p a') states.each do |state| region_name = @api.remove_chars(element.css("#{col} h3").children.to_s) state_name = @api.remove_chars(state.children.to_s) state_rss = "#{::OnTheSnow.config.url}#{state.attributes["href"].value}" state_instance = new(state_name, region_name, state_rss) @states[(@states_count+=1).to_s] = state_instance.to_hash end end } end @states end |
Instance Method Details
#to_hash ⇒ Object
39 40 41 |
# File 'lib/onthesnow/state/state.rb', line 39 def to_hash {"name" => state_name, "region" => region_name, "rss" => state_rss} end |