Class: TrailInfo::State
- Inherits:
-
Object
- Object
- TrailInfo::State
- Defined in:
- lib/trail_info/states.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#trails ⇒ Object
Returns the value of attribute trails.
Class Method Summary collapse
-
.all ⇒ Object
returns all trails for state instance.
-
.clear_all ⇒ Object
clears trails for state instance.
-
.trail_list ⇒ Object
Writes list of states trails.
Instance Method Summary collapse
-
#initialize(name, state_code) ⇒ State
constructor
Creates new state instance and initializes scraping and new trail instances.
Constructor Details
#initialize(name, state_code) ⇒ State
Creates new state instance and initializes scraping and new trail instances
6 7 8 9 10 11 12 13 |
# File 'lib/trail_info/states.rb', line 6 def initialize(name, state_code) #Creates new state instance and initializes scraping and new trail instances @name = name @trails = [] TrailInfo::Scraper.create_trails(state_code).each do |trail| @trails << TrailInfo::Trail.new(self, trail) end @@all << self end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/trail_info/states.rb', line 3 def name @name end |
#trails ⇒ Object
Returns the value of attribute trails.
3 4 5 |
# File 'lib/trail_info/states.rb', line 3 def trails @trails end |
Class Method Details
.all ⇒ Object
returns all trails for state instance
15 16 17 |
# File 'lib/trail_info/states.rb', line 15 def self.all #returns all trails for state instance @@all end |
.clear_all ⇒ Object
clears trails for state instance
19 20 21 |
# File 'lib/trail_info/states.rb', line 19 def self.clear_all #clears trails for state instance @@all.clear end |
.trail_list ⇒ Object
Writes list of states trails
23 24 25 26 27 28 29 30 31 |
# File 'lib/trail_info/states.rb', line 23 def self.trail_list #Writes list of states trails @trail_list = [] @@all[0].trails.each.with_index(1) do |trail, i| trail_description = "#{i}. #{trail.name} | Length: #{trail.length} | Surface: #{trail.surface}|" puts trail_description @trail_list << trail_description end @trail_list end |