Module: Scrapbooker::Utilities

Defined in:
lib/scrapbooker/utilities.rb

Instance Method Summary collapse

Instance Method Details

#configurationObject



8
9
10
# File 'lib/scrapbooker/utilities.rb', line 8

def configuration
  @configuration ||= Configuration.new
end

#configure {|configuration| ... } ⇒ Object

Yields:



4
5
6
# File 'lib/scrapbooker/utilities.rb', line 4

def configure
  yield configuration
end

#last_updateObject



39
40
41
# File 'lib/scrapbooker/utilities.rb', line 39

def last_update
	Time.parse(File.read(timestamp_file))
end

#timestamp_exists?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/scrapbooker/utilities.rb', line 27

def timestamp_exists?
  File.exists?(timestamp_file) ? true : false
end

#timestamp_fileObject



35
36
37
# File 'lib/scrapbooker/utilities.rb', line 35

def timestamp_file
  "#{self.configuration.timestamp_storage}/#{self.name.underscore}_last_update"
end

#timestamp_is_current?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/scrapbooker/utilities.rb', line 23

def timestamp_is_current?
  last_update > self.configuration.update_interval.minutes.ago
end

#update_scrapbookObject



17
18
19
20
21
# File 'lib/scrapbooker/utilities.rb', line 17

def update_scrapbook
  #Get results from active services
  poll_twitter?
  update_timestamp
end

#update_scrapbook?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/scrapbooker/utilities.rb', line 12

def update_scrapbook?
  update_scrapbook if !timestamp_exists?
  update_scrapbook if !timestamp_is_current?
end

#update_timestampObject



31
32
33
# File 'lib/scrapbooker/utilities.rb', line 31

def update_timestamp
  File.open(timestamp_file, "w+") {|f| f.write(Time.now)}
end