Module: Extractula

Defined in:
lib/extractula/custom_extractors/dinosaur_comics.rb,
lib/extractula.rb,
lib/extractula.rb,
lib/extractula/oembed.rb,
lib/extractula/custom_extractors/vimeo.rb,
lib/extractula/custom_extractors/flickr.rb,
lib/extractula/custom_extractors/y_frog.rb,
lib/extractula/custom_extractors/twit_pic.rb,
lib/extractula/custom_extractors/you_tube.rb

Overview

This is mostly a proof-of-concept.

Defined Under Namespace

Modules: OEmbed Classes: DinosaurComics, ExtractedContent, Extractor, Flickr, TwitPic, Vimeo, YFrog, YouTube

Constant Summary collapse

VERSION =
"0.0.11"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.extractorsObject (readonly)

Returns the value of attribute extractors.



18
19
20
# File 'lib/extractula.rb', line 18

def extractors
  @extractors
end

.last_extractorObject (readonly)

Returns the value of attribute last_extractor.



18
19
20
# File 'lib/extractula.rb', line 18

def last_extractor
  @last_extractor
end

Class Method Details

.add_extractor(extractor_class) ⇒ Object



20
21
22
# File 'lib/extractula.rb', line 20

def add_extractor(extractor_class)
  @extractors << extractor_class
end

.custom_extractor(*args, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/extractula.rb', line 38

def custom_extractor(*args, &block)
  config      = args.last.is_a?(Hash) ? args.pop : {}
  klass_name  = args[0]
  if block_given?
    klass = Class.new Extractula::Extractor, &block
  else
    klass = Class.new Extractula::Extractor
    klass.__send__ :include, Extractula::OEmbed if config.delete(:oembed)
    config.each { |option, args| klass.__send__(option, *args) }
  end
  const_set klass_name, klass if klass_name
  klass
end

.extract(url, html) ⇒ Object



28
29
30
31
32
# File 'lib/extractula.rb', line 28

def extract(url, html)
  parsed_url, parsed_html = Domainatrix.parse(url), Nokogiri::HTML(html)
  extractor = select_extractor parsed_url, parsed_html
  extractor.new(parsed_url, parsed_html).extract
end

.remove_extractor(extractor_class) ⇒ Object



24
25
26
# File 'lib/extractula.rb', line 24

def remove_extractor(extractor_class)
  @extractors.delete extractor_class
end

.select_extractor(url, html) ⇒ Object



34
35
36
# File 'lib/extractula.rb', line 34

def select_extractor url, html
  @last_extractor = @extractors.detect {|e| e.can_extract? url, html} || Extractor
end