Class: Bateman::TwitterCard

Inherits:
Object
  • Object
show all
Defined in:
lib/bateman/twitter_card.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ TwitterCard

Returns a new instance of TwitterCard.



5
6
7
8
9
10
11
# File 'lib/bateman/twitter_card.rb', line 5

def initialize(url)
  @uri = URI.parse(url)

  fetch
  process_html_document
  set_attributes_from_response
end

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



3
4
5
# File 'lib/bateman/twitter_card.rb', line 3

def card
  @card
end

#creatorObject (readonly)

Returns the value of attribute creator.



3
4
5
# File 'lib/bateman/twitter_card.rb', line 3

def creator
  @creator
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/bateman/twitter_card.rb', line 3

def description
  @description
end

#imageObject (readonly)

Returns the value of attribute image.



3
4
5
# File 'lib/bateman/twitter_card.rb', line 3

def image
  @image
end

#siteObject (readonly)

Returns the value of attribute site.



3
4
5
# File 'lib/bateman/twitter_card.rb', line 3

def site
  @site
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/bateman/twitter_card.rb', line 3

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/bateman/twitter_card.rb', line 3

def url
  @url
end

Instance Method Details

#fetchObject



23
24
25
26
27
# File 'lib/bateman/twitter_card.rb', line 23

def fetch
  @response = HTTParty.get(@uri.to_s)

  self
end

#process_html_documentObject



29
30
31
32
33
# File 'lib/bateman/twitter_card.rb', line 29

def process_html_document
  @html_document = Nokogiri::HTML(@response.body)

  self
end

#set_attributes_from_responseObject



13
14
15
16
17
18
19
20
21
# File 'lib/bateman/twitter_card.rb', line 13

def set_attributes_from_response
  @card = Bateman::CardAttribute.new(@html_document).to_s
  @creator = Bateman::CreatorAttribute.new(@html_document).to_s
  @description = Bateman::DescriptionAttribute.new(@html_document).to_s
  @image = Bateman::ImageAttribute.new(@html_document).to_s
  @site = Bateman::SiteAttribute.new(@html_document).to_s
  @title = Bateman::TitleAttribute.new(@html_document).to_s
  @url = Bateman::UrlAttribute.new(@html_document, @uri).to_s
end