Class: Stratify::Collector

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/stratify/collector.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.collector_classesObject (readonly)

Returns the value of attribute collector_classes.



63
64
65
# File 'lib/stratify/collector.rb', line 63

def collector_classes
  @collector_classes
end

Class Method Details

.collector_class_for(source) ⇒ Object



73
74
75
# File 'lib/stratify/collector.rb', line 73

def self.collector_class_for(source)
  Collector.collector_classes.find {|clazz| clazz.source == source}
end

.configuration_fields(fields_hash = nil) ⇒ Object



13
14
15
16
# File 'lib/stratify/collector.rb', line 13

def self.configuration_fields(fields_hash = nil)
  @configuration_fields = initialize_configuration_fields(fields_hash) unless fields_hash.nil?
  @configuration_fields || []
end

.configuration_instructions(instructions = nil) ⇒ Object



22
23
24
25
# File 'lib/stratify/collector.rb', line 22

def self.configuration_instructions(instructions = nil)
  @configuration_instructions = instructions unless instructions.nil?
  @configuration_instructions
end

.inherited(subclass) ⇒ Object



68
69
70
71
# File 'lib/stratify/collector.rb', line 68

def self.inherited(subclass)
  super
  Collector.collector_classes << subclass
end

.source(src = nil) ⇒ Object

Define where this collector’s activities originate from (e.g., “Twitter”, “iTunes”)



48
49
50
51
# File 'lib/stratify/collector.rb', line 48

def self.source(src = nil)
  @source = src unless src.nil?
  @source
end

.sourcesObject



57
58
59
60
# File 'lib/stratify/collector.rb', line 57

def self.sources
  unsorted_sources = Collector.collector_classes.map(&:source)
  unsorted_sources.sort_by {|source| source.downcase}
end

Instance Method Details

#activitiesObject

To be implemented by subclasses

Returns a collection of activities to be saved.

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/stratify/collector.rb', line 43

def activities
  raise NotImplementedError
end

#configuration_fieldsObject



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

def configuration_fields
  self.class.configuration_fields
end

#configuration_instructionsObject



27
28
29
# File 'lib/stratify/collector.rb', line 27

def configuration_instructions
  self.class.configuration_instructions
end

#configuration_summaryObject



31
32
33
34
# File 'lib/stratify/collector.rb', line 31

def configuration_summary
  return nil if configuration_fields.empty?
  read_attribute(configuration_fields.first.name)
end

#runObject



36
37
38
# File 'lib/stratify/collector.rb', line 36

def run
  Archiver.new(self).run
end

#sourceObject



53
54
55
# File 'lib/stratify/collector.rb', line 53

def source
  self.class.source
end