0
我保留我的代碼D.R.Y.並且想要保存下面的第一個實例變量(@most_recent_game_tr
),所以我可以稍後調用它作爲SomeObject
並獲得它的td:nth-child(x).text
。您可以使用哪種(不一定)Nokogiri方法來實現這一點?將表格行作爲對象(?)使用Nokogiri
@most_recent_game_tr = doc.css("#games tbody tr:nth-child(#{game_played})")
@result = doc.css("#games tbody tr:nth-child(#{game_played}) td:nth-child(6)").text
@opponent_name = doc.css("#games tbody tr:nth-child(#{game_played}) td:nth-child(5)").text
@rangers = doc.css("#games tbody tr:nth-child(#{game_played}) td:nth-child(8)").text
@extra_time = doc.css("#games tbody tr:nth-child(#{game_played}) td:nth-child(7)").text
@opponent = doc.css("#games tbody tr:nth-child(#{game_played}) td:nth-child(9)").text
@date_result = Date.parse(doc.css("#games tbody tr:nth-child(#{game_played}) td:nth-child(2)").text)
@date = Date.parse(doc.css("#games tbody tr:nth-child(#{game_played + 1}) td:nth-child(2)").text)
這很難說什麼是因爲你沒有告訴我們原始的HTML是什麼樣子的最佳方式。 – 2014-12-15 19:27:31