- def self.find_t comic_id, t
- Story.find(:first, :conditions => ['comic_id = ? and t = ?', comic_id, t])
- end
-
- def self.collect_t story
- r = Story.find(:all, :conditions => ['comic_id = ?', story.comic_id], :order => 't')
- r.map {|s| s.t}
- end
-
- def self.serial? ary
- i = 0
- ary.compact.sort.each do |t|
- break false unless t == i
- i += 1
- end
- ary.compact.size == i
- end
-
- def self.validate_t story
- Story.serial?(Story.collect_t(story))
- end
-
- def insert_shift
- Story.update_all('t = t + 1', ['comic_id = ? and t >= ?', self.comic_id, self.t])
- end
-
- def lesser_shift old_t
- self.t = 0 if self.t < 0
- Story.update_all('t = t + 1', ['comic_id = ? and (t >= ? and t < ?)', self.comic_id, self.t, old_t])
- end
-
- def higher_shift old_t
- nf = Story.find_t(self.comic_id, self.t)
- max_t = Story.max_t(self.comic_id).to_i
- self.t = max_t if self.t > max_t
- Story.update_all('t = t - 1', ['comic_id = ? and (t > ? and t <= ?)', self.comic_id, old_t, self.t])