Class: Vore::Handlers::MetaExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/vore/handlers/meta_extractor.rb

Constant Summary collapse

SELECTOR =
Selma::Selector.new(match_element: "*", match_text_within: "title")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetaExtractor

Returns a new instance of MetaExtractor.



10
11
12
13
14
15
# File 'lib/vore/handlers/meta_extractor.rb', line 10

def initialize
  super
  @title = ""
  @meta = {}
  @within_title = false
end

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/vore/handlers/meta_extractor.rb', line 8

def meta
  @meta
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/vore/handlers/meta_extractor.rb', line 8

def title
  @title
end

Instance Method Details

#handle_element(element) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vore/handlers/meta_extractor.rb', line 21

def handle_element(element)
  if element.tag_name == "title"
    @within_title = true

    element.remove
  elsif element.tag_name == "meta"
    return if element.attributes["name"].nil?

    @meta[element.attributes["name"]] = element.attributes["content"]
  end
end

#handle_text_chunk(text) ⇒ Object



33
34
35
36
37
38
# File 'lib/vore/handlers/meta_extractor.rb', line 33

def handle_text_chunk(text)
  if @within_title
    @within_title = false
    @title = text.to_s
  end
end

#selectorObject



17
18
19
# File 'lib/vore/handlers/meta_extractor.rb', line 17

def selector
  SELECTOR
end