Class: EroGetter

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

Defined Under Namespace

Classes: Base, Livedoor

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_mapping(regex, strategy) ⇒ Object



30
31
32
# File 'lib/ero_getter.rb', line 30

def add_mapping(regex, strategy)
  url_mapping[regex] = strategy
end

.cleanObject



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

def clean
  @url_mapping = {}
end

.directoryObject



20
21
22
23
24
# File 'lib/ero_getter.rb', line 20

def directory
  path = File.join ENV['HOME'], 'ero_getter'
  puts path unless Dir.exists?(path)
  path
end

.url_mappingObject



26
27
28
# File 'lib/ero_getter.rb', line 26

def url_mapping
  @url_mapping ||= {}
end

Instance Method Details

#detect(url) ⇒ Object



5
6
7
8
9
10
# File 'lib/ero_getter.rb', line 5

def detect(url)
  self.class.url_mapping.each_pair do |regex, klazz|
    return klazz if url.match regex
  end
  nil
end

#download(url) ⇒ Object



12
13
14
15
16
# File 'lib/ero_getter.rb', line 12

def download(url)
  klazz = detect(url)
  raise unless klazz
  klazz.new(url).run
end