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
-
.ingesters ⇒ Object
readonly
Returns the value of attribute ingesters.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#subconfig ⇒ Object
readonly
Returns the value of attribute subconfig.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #configure ⇒ Object
- #each ⇒ Object
- #ingest(url) ⇒ Object
- #initialize(config = nil) ⇒ Object
- #to_yaml ⇒ Object
- #write ⇒ Object
Class Attribute Details
.ingesters ⇒ Object (readonly)
Returns the value of attribute ingesters.
10 11 12 |
# File 'lib/purdie/ingester.rb', line 10 def ingesters @ingesters end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/purdie/ingester.rb', line 5 def config @config end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
5 6 7 |
# File 'lib/purdie/ingester.rb', line 5 def matcher @matcher end |
#subconfig ⇒ Object (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 |
#configure ⇒ Object
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 |
#each ⇒ Object
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_yaml ⇒ Object
54 55 56 |
# File 'lib/purdie/ingester.rb', line 54 def to_yaml @items.to_yaml end |
#write ⇒ Object
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 |