Class: RailsParseHead::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_parse_head/base.rb

Direct Known Subclasses

Fetch, Parse

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#htmlObject

Returns the value of attribute html.



8
9
10
# File 'lib/rails_parse_head/base.rb', line 8

def html
  @html
end

Instance Method Details



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_parse_head/base.rb', line 29

def links
  html.css('link').map do |node|
    {
      rel: node['rel'],
      href: node['href'],
      type: node['type'],
      title: node['title'],
      sizes: node['sizes'],
      hreflang: node['hreflang']
    }.compact
  end
end

#metasObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails_parse_head/base.rb', line 15

def metas
  html.css('meta').map do |node|
    {
      name: node['name'],
      property: node['property'],
      content: node['content'],
      itemprop: node['itemprop'],
      description: node['description'],
      class: node['class'],
      charset: node['charset']
    }.compact
  end
end

#titleObject



10
11
12
13
# File 'lib/rails_parse_head/base.rb', line 10

def title
  title = html.at_css('title')
  title.nil? ? '' : title.text
end