Module: TwitterDescription
- Includes:
- DescriptionHelper
- Included in:
- BrilliantWebScraper
- Defined in:
- lib/parsers/twitter_description.rb
Overview
Grep twitter description from attribute ‘twitter:description`
Instance Method Summary collapse
Instance Method Details
#grep_twitter_description(response) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/parsers/twitter_description.rb', line 6 def grep_twitter_description(response) return if response.nil? || response.empty? first_regex = %r{(?im)<meta\s+[\w\s"'=-]*(?:name|itemprop)\s*=\s*(?:'|")?\s*twitter:description\s*(?:'|")?[\w\s"'=-]*content\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)'))[\w\s"'=-]*[\/>]} second_regex = %r{(?im)<meta\s+[\w\s"'=-]*content\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)'))[\w\s"'=-]*(?:name|itemprop)\s*=\s*(?:'|")?\s*twitter:description\s*(?:'|")?[\w\s"'=-]*[\/>]} scrape_description(response, [first_regex, second_regex]) end |