Class: Ballpark
- Inherits:
-
Object
- Object
- Ballpark
- Includes:
- Helpers
- Defined in:
- lib/yabo_tracker/ballpark.rb
Constant Summary
Constants included from Helpers
Instance Attribute Summary collapse
-
#homeruns ⇒ Object
readonly
Returns the value of attribute homeruns.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name_fragment, year = 2015) ⇒ Ballpark
constructor
A new instance of Ballpark.
Methods included from Helpers
build_base_url, generate_nokogiri_html
Constructor Details
#initialize(name_fragment, year = 2015) ⇒ Ballpark
Returns a new instance of Ballpark.
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 |
# File 'lib/yabo_tracker/ballpark.rb', line 10 def initialize(name_fragment, year=2015) url = "http://www.hittrackeronline.com/stadiums.php" html = Helpers.generate_nokogiri_html(url) links = html.css("table.forumline tr td:nth-of-type(2) a") name = nil case year when 2015 id = nil match_counter = 0 links.each do |link| if link.text.downcase.include? name_fragment.downcase match_counter += 1 href = link['href'] id = href[/id=([^&]*)/].gsub('id=', '') name = link.text end end raise "No ballpark by that name!" if id.nil? raise "Multiple matching ballparks, be more specific!" if match_counter > 1 else raise "No data for that year" end @name = name @homeruns = Homerun.homers_for_id(id) end |
Instance Attribute Details
#homeruns ⇒ Object (readonly)
Returns the value of attribute homeruns.
6 7 8 |
# File 'lib/yabo_tracker/ballpark.rb', line 6 def homeruns @homeruns end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/yabo_tracker/ballpark.rb', line 6 def name @name end |