Class: Place::TimePoint

Inherits:
Ohm::Model
  • Object
show all
Defined in:
lib/place/time_point.rb

Overview

A TimePoint is a “named milestone”

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.rulesObject

Returns the value of attribute rules.



17
18
19
# File 'lib/place/time_point.rb', line 17

def rules
  @rules
end

Class Method Details

.collect_all(base_url) ⇒ Object

Collect all timepoints (url) under a given project url



25
26
27
28
29
30
31
32
33
34
# File 'lib/place/time_point.rb', line 25

def self.collect_all(base_url)
  Dir.glob(base_url + '/tracker/timepoints/*.xml').each do |filename|
 TimePoint.create(
:tid		=> File.basename(filename, '.xml'),
:url		=> filename,
:project	=> Project.find_by_url(base_url)
 )
 Place.logger.info("collected timepoint at #{filename}")
	end
end

.find_by_tid(tid) ⇒ Object



48
49
50
51
52
# File 'lib/place/time_point.rb', line 48

def self.find_by_tid(tid)
  return nil  if tid.nil?
  tps = self.find(:tid => tid.to_s)
	tps.nil? ? nil : tps[0]
end

Instance Method Details

#retrieveObject

Retrieve a specific timepoint data (name, time, description)



37
38
39
40
41
42
43
44
45
46
# File 'lib/place/time_point.rb', line 37

def retrieve
  content = IO.readlines(url).join('')
	doc = Nokogiri::XML(content)
	self.class.rules.each_pair do |k,v|
 tmp = doc.xpath(v)
 self.send("#{k}=", tmp[0].content)  unless tmp[0].nil?		
	end
	Place.logger.info("retrieved timepoint #{self.url}")
  self.save
end