Class: Article
- Inherits:
-
Object
- Object
- Article
- Defined in:
- lib/article.rb
Overview
The Article class contains the links and tags for consumption by twitter
Constant Summary collapse
- TAG_CSS =
CSS tag to pull the tags strings
'.tags a'
Instance Attribute Summary collapse
-
#link ⇒ Object
Returns the value of attribute link.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#tweets ⇒ Object
Returns the value of attribute tweets.
Instance Method Summary collapse
-
#build_tweets ⇒ Object
Recursively build and populate tweets.
-
#filter_tags(document) ⇒ Object
Filters finds the link inside the .g-tag-box div, pulls the name, then makes the resulting string uppercase.
-
#initialize(link) ⇒ Article
constructor
A new instance of Article.
-
#request_url ⇒ Object
Opens @link, then parses using Nokogiri.
-
#retrieve_tags ⇒ Object
sets @tags by calling the url, then filtering the document to find the tags.
Constructor Details
#initialize(link) ⇒ Article
Returns a new instance of Article.
13 14 15 16 |
# File 'lib/article.rb', line 13 def initialize(link) @link = link @tweets = [] end |
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link.
8 9 10 |
# File 'lib/article.rb', line 8 def link @link end |
#tags ⇒ Object
Returns the value of attribute tags.
8 9 10 |
# File 'lib/article.rb', line 8 def @tags end |
#tweets ⇒ Object
Returns the value of attribute tweets.
7 8 9 |
# File 'lib/article.rb', line 7 def tweets @tweets end |
Instance Method Details
#build_tweets ⇒ Object
Recursively build and populate tweets. This will catch any errors which are raised by Tweet#add and attempt to call it again
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/article.rb', line 20 def build_tweets # rubocop:disable Metrics/MethodLength tweet = Tweet.new(@link) @tags.each do |tag| begin tweet.add(tag) rescue Tweet::TagTooLong @tweets.push tweet raise StandardError if "#{tag} | #{@link}".length > 140 tweet = Tweet.new(@link) end end @tweets.push tweet end |
#filter_tags(document) ⇒ Object
Filters finds the link inside the .g-tag-box div, pulls the name, then makes the resulting string uppercase.
49 50 51 52 |
# File 'lib/article.rb', line 49 def (document) # Filter down and get the tags. @tags = document.css(TAG_CSS).map(&:children).map(&:text) end |
#request_url ⇒ Object
Opens @link, then parses using Nokogiri
55 56 57 58 |
# File 'lib/article.rb', line 55 def request_url # Get all data Nokogiri::HTML(open(@link)) end |
#retrieve_tags ⇒ Object
sets @tags by calling the url, then filtering the document to find the tags.
40 41 42 43 44 45 |
# File 'lib/article.rb', line 40 def # get post doc = request_url @tags = (doc) self end |