Class: Ubiquitously::Page
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#image ⇒ Object
Returns the value of attribute image.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Page
constructor
A new instance of Page.
- #parse ⇒ Object
Methods inherited from Base
Methods included from SubclassableCallbacks
Constructor Details
#initialize(attributes = {}) ⇒ Page
Returns a new instance of Page.
5 6 7 |
# File 'lib/ubiquitously/models/page.rb', line 5 def initialize(attributes = {}) apply attributes end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/ubiquitously/models/page.rb', line 3 def description @description end |
#image ⇒ Object
Returns the value of attribute image.
3 4 5 |
# File 'lib/ubiquitously/models/page.rb', line 3 def image @image end |
#tags ⇒ Object
Returns the value of attribute tags.
3 4 5 |
# File 'lib/ubiquitously/models/page.rb', line 3 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/ubiquitously/models/page.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/ubiquitously/models/page.rb', line 3 def url @url end |
Instance Method Details
#parse ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ubiquitously/models/page.rb', line 9 def parse html = Nokogiri::HTML(open(url).read) self.title = html.xpath("//title").first.text.to_s.strip self.description = html.xpath("//meta[@name='description']").first["content"] rescue "" self.description.strip! self. = html.xpath("//meta[@name='keywords']").first["content"] rescue "" self. = self..split(/,\s+/).taggify("-", ", ").split(", ") self.image = html.xpath("//link[@rel='image_src']").first["image_src"] rescue nil if self.image.blank? self.image = html.xpath("//img").first["src"] rescue nil end self end |