Class: Arrogance::DataHandler
- Inherits:
-
Object
- Object
- Arrogance::DataHandler
- Defined in:
- lib/arrogance/tools.rb
Overview
– This gathers information on the feed, such as the site link and feed image
Instance Attribute Summary collapse
-
#feed_image ⇒ Object
Returns the value of attribute feed_image.
-
#feed_title ⇒ Object
Returns the value of attribute feed_title.
-
#site_link ⇒ Object
Returns the value of attribute site_link.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #discover_data ⇒ Object
- #discover_feed_image(doc) ⇒ Object
- #discover_feed_title(doc) ⇒ Object
- #discover_site_link(doc) ⇒ Object
-
#initialize(url) ⇒ DataHandler
constructor
A new instance of DataHandler.
Constructor Details
#initialize(url) ⇒ DataHandler
Returns a new instance of DataHandler.
162 163 164 165 |
# File 'lib/arrogance/tools.rb', line 162 def initialize(url) self.url = url discover_data end |
Instance Attribute Details
#feed_image ⇒ Object
Returns the value of attribute feed_image.
160 161 162 |
# File 'lib/arrogance/tools.rb', line 160 def feed_image @feed_image end |
#feed_title ⇒ Object
Returns the value of attribute feed_title.
160 161 162 |
# File 'lib/arrogance/tools.rb', line 160 def feed_title @feed_title end |
#site_link ⇒ Object
Returns the value of attribute site_link.
160 161 162 |
# File 'lib/arrogance/tools.rb', line 160 def site_link @site_link end |
#url ⇒ Object
Returns the value of attribute url.
160 161 162 |
# File 'lib/arrogance/tools.rb', line 160 def url @url end |
Instance Method Details
#discover_data ⇒ Object
167 168 169 170 171 172 |
# File 'lib/arrogance/tools.rb', line 167 def discover_data doc = Nokogiri::XML(open(self.url)).remove_namespaces! [:discover_feed_title, :discover_feed_image, :discover_site_link].each do |meth| self.send(meth, doc) end end |
#discover_feed_image(doc) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/arrogance/tools.rb', line 186 def discover_feed_image(doc) unless (img = doc.xpath('//channel//image//url').inner_text).empty? self.feed_image = img.to_s else #-- for some reason this is causing a seg-fault. hope to get to the bottom of it #-- in fact, someone should really get to the bottom of why ruby seg-faults on most #-- gems written in C. C is for cool, guys, lets show it some love. #unless doc.xpath('//channel//image').to_s.empty? # tag = doc.xpath('//channel//image').to_s # self.feed_image = /".*?"/.match(tag).to_s #else self.feed_image = '' #end end end |
#discover_feed_title(doc) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/arrogance/tools.rb', line 174 def discover_feed_title(doc) xpath = doc.xpath('//channel//title') unless (ft = xpath.inner_text).empty? self.feed_title = doc.xpath('//channel//title').inner_text.to_s if ft.length > 50 self.feed_title = xpath[0].inner_text end else self.feed_title = '' end end |
#discover_site_link(doc) ⇒ Object
203 204 205 206 207 208 209 |
# File 'lib/arrogance/tools.rb', line 203 def discover_site_link(doc) link = doc.xpath('//channel//link').inner_text.to_s if link.length > 49 link = /(.*?.com).*?/.match(link)[0] end self.site_link = link end |