class ScrapCbf::RoundsBuilder
Public Class Methods
new(document, championship)
click to toggle source
# File lib/scrap_cbf/builders/rounds_builder.rb, line 11 def initialize(document, championship) @championship = championship @rounds = [] scrap_rounds(document) end
Public Instance Methods
matches_builder()
click to toggle source
# File lib/scrap_cbf/builders/rounds_builder.rb, line 18 def matches_builder matches = @rounds.reduce([]) do |arr, round| matches_per_round = round.matches arr.push(*matches_per_round.all) end MatchesBuilder.new(matches) end
to_h()
click to toggle source
# File lib/scrap_cbf/builders/rounds_builder.rb, line 27 def to_h @rounds.map(&:to_h) end
Private Instance Methods
scrap_matches(round, round_element)
click to toggle source
# File lib/scrap_cbf/builders/rounds_builder.rb, line 61 def scrap_matches(round, round_element) round_element.children.each do |element| # matches are founded on <ul> next unless element.element? && element.name == 'ul' round.matches = MatchesPerRoundBuilder.new( element, round.number, @championship ) end round end
scrap_round(round_element, round_number)
click to toggle source
# File lib/scrap_cbf/builders/rounds_builder.rb, line 49 def scrap_round(round_element, round_number) round = Round.new round.championship = @championship.year round.serie = @championship.serie # Because index starts on zero, we add 1 for matching with Rounds ID round.number = round_number + 1 scrap_matches(round, round_element) round end
scrap_rounds(rounds_elements)
click to toggle source
# File lib/scrap_cbf/builders/rounds_builder.rb, line 33 def scrap_rounds(rounds_elements) (0..37).each do |round_number| round_element = rounds_elements.css( "div[data-slide-index=#{round_number}]" ) round_element.children.each do |element| next unless element.element? && element.name == 'div' round = scrap_round(element, round_number) @rounds << round end end end