Class: Trio::Blog::API::PostAttributes

Inherits:
DocumentReader show all
Defined in:
lib/trio/blog/api/post_attributes.rb

Instance Attribute Summary collapse

Attributes inherited from DocumentReader

#config, #document

Instance Method Summary collapse

Constructor Details

#initialize(selectors, document, config) ⇒ PostAttributes

Returns a new instance of PostAttributes.



9
10
11
12
# File 'lib/trio/blog/api/post_attributes.rb', line 9

def initialize(selectors, document, config)
  super(document, config)
  @selectors = selectors
end

Instance Attribute Details

#selectorsObject (readonly)

Returns the value of attribute selectors.



7
8
9
# File 'lib/trio/blog/api/post_attributes.rb', line 7

def selectors
  @selectors
end

Instance Method Details

#author_avatar_image_urlObject



35
36
37
# File 'lib/trio/blog/api/post_attributes.rb', line 35

def author_avatar_image_url
  selectors.author_avatar_image_element.attr("data-src") || raise(EmptyAttributeError.new(__method__))
end

#author_nameObject



31
32
33
# File 'lib/trio/blog/api/post_attributes.rb', line 31

def author_name
  selectors.author_name_element.text || raise(EmptyAttributeError.new(__method__))
end

#post_urlObject



22
23
24
25
26
27
28
29
# File 'lib/trio/blog/api/post_attributes.rb', line 22

def post_url
  post_url = selectors.post_link_element.attr("href") || raise(EmptyAttributeError.new(__method__))
  parsed_post_url = URI.parse(post_url)
  base_url = URI.parse(config.base_url)
  parsed_post_url.host = base_url.host
  parsed_post_url.scheme = base_url.scheme
  parsed_post_url.to_s
end

#thumbnail_image_urlObject



18
19
20
# File 'lib/trio/blog/api/post_attributes.rb', line 18

def thumbnail_image_url
  selectors.thumbnail_image_element.attr("data-src") || raise(EmptyAttributeError.new(__method__))
end

#titleObject



14
15
16
# File 'lib/trio/blog/api/post_attributes.rb', line 14

def title
  selectors.title_element.text || raise(EmptyAttributeError.new(__method__))
end