Module: ScrapCbf::MatchesHelper
- Includes:
- DepthSearch
- Included in:
- MatchesPerRoundBuilder
- Defined in:
- lib/scrap_cbf/helpers/matches_helper.rb
Instance Method Summary collapse
-
#date_with_start_at_helper(date, start_at) ⇒ Object
03/02/2021 16:00.
-
#find_info_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
-
#find_place_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 4 methods in 1.
-
#find_score_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
-
#find_start_at_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
-
#find_updates_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
-
#score_by_team_helper(team, score) ⇒ Object
e.g 0 x 1.
-
#scrap_team_names_helper(team_element) ⇒ Object
teams are extract from <img>.
Methods included from DepthSearch
Instance Method Details
#date_with_start_at_helper(date, start_at) ⇒ Object
03/02/2021 16:00
20 21 22 23 24 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 20 def date_with_start_at_helper(date, start_at) return unless date && start_at "#{date} #{start_at}" end |
#find_info_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
pass assertive Proc to depth_search
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 39 def find_info_helper(match) find = proc do |element| if element.text? formatted_text = element.text.strip unless formatted_text.empty? res = formatted_text.match?( /Jogo: \d{1,3}$/i ) next formatted_text if res end end nil end depth_search(match, find) end |
#find_place_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 4 methods in 1.
pass assertive Proc to depth_search
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 119 def find_place_helper(match) find = proc do |element| if element.text? formatted_text = element.text.strip unless formatted_text.empty? res = formatted_text.match?( /^[a-záàâãéèêíïóôõöúçñ\-\s]+ - [a-záàâãéèêíïóôõöúçñ\s\-]+ - [A-Z]{2}$/i ) next formatted_text if res end end nil end depth_search(match, find) end |
#find_score_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
pass assertive Proc to depth_search
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 99 def find_score_helper(match) find = proc do |element| if element.text? formatted_text = element.text.strip unless formatted_text.empty? res = formatted_text.match?( /^\d{1} x \d{1}$/i ) next formatted_text if res end end nil end depth_search(match, find) end |
#find_start_at_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
pass assertive Proc to depth_search
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 79 def find_start_at_helper(match) find = proc do |element| if element.text? formatted_text = element.text.strip unless formatted_text.empty? res = formatted_text.match?( /^\d{2}:\d{2}$/i ) next formatted_text if res end end nil end depth_search(match, find) end |
#find_updates_helper(match) ⇒ Object
Because of problem passing regex, couldn’t turn the 5 methods in 1.
pass assertive Proc to depth_search
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 59 def find_updates_helper(match) find = proc do |element| if element.text? formatted_text = element.text.strip unless formatted_text.empty? res = formatted_text.match?( /\d{1} (ALTERAÇÃO|ALTERAÇÕES)$/i ) next formatted_text if res end end nil end depth_search(match, find) end |
#score_by_team_helper(team, score) ⇒ Object
e.g 0 x 1
10 11 12 13 14 15 16 17 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 10 def score_by_team_helper(team, score) case team when :team score.split(' ')[0].to_i if score when :opponent score.split(' ')[2].to_i if score end end |
#scrap_team_names_helper(team_element) ⇒ Object
teams are extract from <img>
27 28 29 30 31 32 33 34 |
# File 'lib/scrap_cbf/helpers/matches_helper.rb', line 27 def scrap_team_names_helper(team_element) if team_element.key?('title') && team_element['title'].match?(/^[a-záàâãéèêíïóôõöúç\s]+ - [a-z]{2}$/i) # Extract team's name (e.g Santos - SP => Santos) team_element['title'][/^[a-záàâãéèêíïóôõöúç\s]{3,50}/i].strip end end |