diff --git a/Library/Homebrew/livecheck/strategy/page_match.rb b/Library/Homebrew/livecheck/strategy/page_match.rb index 0249c3629b..4e778bae6f 100644 --- a/Library/Homebrew/livecheck/strategy/page_match.rb +++ b/Library/Homebrew/livecheck/strategy/page_match.rb @@ -46,21 +46,22 @@ module Homebrew # @param regex [Regexp] a regex used for matching versions in the # content # @return [Array] - def self.page_matches(url, regex) + def self.page_matches(url, regex, &block) page = Strategy.page_contents(url) - matches = page.scan(regex) - - regex_names = regex.names.map(&:to_sym) - - if regex_names.count > 1 - matches.map do |match| - match_data = regex_names.zip(match).to_h - regex_names.sort.map { |name| match_data[name] }.join(",") - end.uniq - else - matches.map(&:first).uniq + if block + data = { page: page } + case (value = block.call(data)) + when String + return [value] + when Array + return value + else + raise TypeError, "Return value of `strategy :page_match` block must be a string or array." + end end + + page.scan(regex).map(&:first).uniq end # Checks the content at the URL for new versions, using the provided @@ -69,10 +70,10 @@ module Homebrew # @param url [String] the URL of the content to check # @param regex [Regexp] a regex used for matching versions in content # @return [Hash] - def self.find_versions(url, regex) + def self.find_versions(url, regex, &block) match_data = { matches: {}, regex: regex, url: url } - page_matches(url, regex).each do |match| + page_matches(url, regex, &block).each do |match| match_data[:matches][match] = Version.new(match) end