Module: Purdie::Ingester

Includes:
Enumerable
Included in:
Services::Flickr, Services::SoundCloud, Services::Vimeo, Services::YouTube
Defined in:
lib/purdie/ingester.rb

Defined Under Namespace

Modules: ClassMethods

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.ingestersObject (readonly)

Returns the value of attribute ingesters.



10
11
12
# File 'lib/purdie/ingester.rb', line 10

def ingesters
  @ingesters
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/purdie/ingester.rb', line 5

def config
  @config
end

#matcherObject (readonly)

Returns the value of attribute matcher.



5
6
7
# File 'lib/purdie/ingester.rb', line 5

def matcher
  @matcher
end

#subconfigObject (readonly)

Returns the value of attribute subconfig.



5
6
7
# File 'lib/purdie/ingester.rb', line 5

def subconfig
  @subconfig
end

Class Method Details

.included(base) ⇒ Object



15
16
17
18
19
# File 'lib/purdie/ingester.rb', line 15

def self.included base
  # Voodoo: http://stackoverflow.com/questions/10692961/inheriting-class-methods-from-mixins
  base.extend ClassMethods
  @ingesters.push base
end

Instance Method Details

#[](key) ⇒ Object



50
51
52
# File 'lib/purdie/ingester.rb', line 50

def [] key
  @items[key]
end

#configureObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/purdie/ingester.rb', line 29

def configure
  @output_file = "#{@config['output_dir']}/#{Purdie.basename(self).downcase}.yaml"
  specific_config = @config['services'][Purdie.basename self] rescue nil

  if specific_config
    specific_config.each_pair do |key, value|
      self.instance_variable_set("@#{key}", value)
    end
  end
end

#eachObject



44
45
46
47
48
# File 'lib/purdie/ingester.rb', line 44

def each
  @items.each do |item|
    yield item
  end
end

#ingest(url) ⇒ Object



40
41
42
# File 'lib/purdie/ingester.rb', line 40

def ingest url
  @items.push distill url
end

#initialize(config = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/purdie/ingester.rb', line 21

def initialize config = nil
  config = Config.instance.config unless config
  @config = config
  @items = []

  configure
end

#to_yamlObject



54
55
56
# File 'lib/purdie/ingester.rb', line 54

def to_yaml
  @items.to_yaml
end

#writeObject



58
59
60
61
62
63
64
65
# File 'lib/purdie/ingester.rb', line 58

def write
  if self.any?
    FileUtils.mkdir_p File.dirname @output_file
    File.open @output_file, 'w' do |f|
      f.write self.to_yaml
    end
  end
end