内部にオブジェクトがある配列をソートしようとすると、次のエラーが発生します
未定義のメソッド `match_id' #
sort を呼び出さずにオブジェクトを正常に戻しています(両方のソート試行で同じエラーが発生します)
get '/' do
content_type :json
@matches = []
build_matches_object(@matches, 'C:\Users\Steve\Desktop\BoxRec Boxing Records_files\BoxRec Boxing Records.htm')
@matches.sort! { |a,b| a.match_id <=> b.match_id }
#@matches.sort_by { |a| [a.match_id] }
@matches.to_json
end
オブジェクトは次の関数で作成されます (build_matches_object)
def build_matches_object(myscrape, boxrec_path)
doc = Nokogiri::HTML(open(boxrec_path))
match_date = ''
doc.xpath("//table[@align='center'][not(@id) and not(@class)]/tr").each do |trow|
#Try get the date
if trow.css('.show_left b').length == 1
match_date = trow.css('.show_left b').first.content
match_date = Time.parse(match_date)
end
#if a match row
if trow.css('td a').length == 2 and trow.css('* > td').length > 10
#CODE REMOVED THAT GETS THE BELOW VARIABLES USED TO BUILD MATCH (KNOW IT RETURNS THEM FINE
#create the match object
match = {
:number_of_rounds => trow.css('td:nth-child(3)').first.content.to_i,
:weight_division => trow.css('td:nth-child(4)').first.content,
:first_boxer_name => first_boxer_td.css('a').first.content,
:first_boxer_href => first_boxer_href,
:second_boxer_name => second_boxer_td.css('a').first.content,
:second_boxer_href => second_boxer_href,
:date_of_match => match_date,
:rating => rating,
:match_id => matchid
}
myscrape.push(match)
end
end
end
私が間違っているのは何ですか?