Class: HikingGuide::Trail

Inherits:
Object
  • Object
show all
Defined in:
lib/hiking_guide/trail.rb

Constant Summary collapse

@@all =
[]
@@md =
[]
@@pa =
[]
@@nc =
[]
@@va =
[]
@@wv =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trail_hash) ⇒ Trail

Returns a new instance of Trail.



10
11
12
13
14
# File 'lib/hiking_guide/trail.rb', line 10

def initialize(trail_hash)
  trail_hash.each {|key, value| self.send("#{key}=", "#{value}")}
  HikingGuide::Trail.all << self
  HikingGuide::Trail.update_state_lists
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def description
  @description
end

#elevation_gainObject

Returns the value of attribute elevation_gain.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def elevation_gain
  @elevation_gain
end

#hiking_timeObject

Returns the value of attribute hiking_time.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def hiking_time
  @hiking_time
end

#lengthObject

Returns the value of attribute length.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def length
  @length
end

Returns the value of attribute map_pdf_link.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def map_pdf_link
  @map_pdf_link
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def name
  @name
end

#profile_urlObject

Returns the value of attribute profile_url.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def profile_url
  @profile_url
end

#stateObject

Returns the value of attribute state.



2
3
4
# File 'lib/hiking_guide/trail.rb', line 2

def state
  @state
end

Class Method Details

.allObject



45
46
47
# File 'lib/hiking_guide/trail.rb', line 45

def self.all
  @@all
end

.create_from_collection(trails_array) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/hiking_guide/trail.rb', line 16

def self.create_from_collection(trails_array)
  trails_array.each do |trail|
    if HikingGuide::Trail.all.include?(trail) == false
      HikingGuide::Trail.new(trail)
    end
  end
end

.mdObject



49
50
51
# File 'lib/hiking_guide/trail.rb', line 49

def self.md
  @@md
end

.ncObject



57
58
59
# File 'lib/hiking_guide/trail.rb', line 57

def self.nc
  @@nc
end

.paObject



53
54
55
# File 'lib/hiking_guide/trail.rb', line 53

def self.pa
  @@pa
end

.reset_allObject



69
70
71
72
73
74
75
76
# File 'lib/hiking_guide/trail.rb', line 69

def self.reset_all
  @@all.clear
  @@md.clear
  @@pa.clear
  @@nc.clear
  @@va.clear
  @@wv.clear
end

.update_state_listsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hiking_guide/trail.rb', line 28

def self.update_state_lists
  self.all.each do |trail|
    case trail.state
    when "MD"
      self.md.include?(trail) ? nil : self.md << trail
    when "PA"
      self.pa.include?(trail) ? nil : self.pa << trail
    when "NC"
      self.nc.include?(trail) ? nil : self.nc << trail
    when "VA"
      self.va.include?(trail) ? nil : self.va << trail
    when "WV"
      self.wv.include?(trail) ? nil : self.wv << trail
    end
  end
end

.vaObject



61
62
63
# File 'lib/hiking_guide/trail.rb', line 61

def self.va
  @@va
end

.wvObject



65
66
67
# File 'lib/hiking_guide/trail.rb', line 65

def self.wv
  @@wv
end

Instance Method Details

#add_trail_attributes(attributes_hash) ⇒ Object



24
25
26
# File 'lib/hiking_guide/trail.rb', line 24

def add_trail_attributes(attributes_hash)
  attributes_hash.each {|key, value| self.send("#{key}=", "#{value}")}
end