Class: Worldfootball::Page::Team
- Inherits:
-
Worldfootball::Page
- Object
- Worldfootball::Page
- Worldfootball::Page::Team
- Defined in:
- lib/worldfootball/page_team.rb
Overview
note: use nested class for now - why? why not?
Constant Summary
Constants inherited from Worldfootball::Page
Class Method Summary collapse
Instance Method Summary collapse
-
#props ⇒ Object
rename to properties or attributes or ?? or infobox or data or ?? why? why not?.
Methods inherited from Worldfootball::Page
#assert, #debug?, #doc, from_file, #generated, #generated_in_days_ago, #initialize, #keywords, #log, #squish, #title, #url
Constructor Details
This class inherits a constructor from Worldfootball::Page
Class Method Details
Instance Method Details
#props ⇒ Object
rename to properties or attributes or ??
or infobox or data or ?? why? why not?
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/worldfootball/page_team.rb', line 15 def props = doc.css( 'div.sidebar' ).first assert( , 'no div.sidebar found in team page!!' ) h2 = .css( 'h2' ).first assert( h2, 'no h2 inside div.sidebar found in team page!!') name = h2.text table = .css( 'table' ).first assert( table, 'no table inside div.sidebar found in team page!!') long_name = nil country = nil ground = nil founded = nil trs = table.css( 'tr' ) trs.each_with_index do |tr,i| text = squish(tr.text) ## puts "[#{i+1}] >#{text}<" ## assume long name first column if NOT starting w/ Land: if i==0 && !text.start_with?( 'Land' ) long_name = text end if text.start_with?( 'Land:' ) country = text.sub( 'Land:', '' ).strip end if text.start_with?( 'gegründet:' ) founded = text.sub( 'gegründet:', '' ).strip end if text.start_with?( 'Stadion:' ) ground = text.sub( 'Stadion:', '' ).strip end end data = { name: name } data[ :long_name] = long_name if long_name data[ :country ] = country if country data[ :founded ] = founded if founded && founded != '0000' data[ :ground] = ground if ground && ground != '----------' data end |