class TrackBlockOrigin

Constants

MIN_SECONDS_PER_BLOCK
TRACK_MAX_BLOCKS

Public Instance Methods

get_block_idx_by_second(second) click to toggle source
# File lib/ting_model/track_block_origin.rb, line 28
def get_block_idx_by_second(second)
  if second
    second = second.to_i
    next_flag = self.flags.split(',').map{|s| s.to_f}.index{|x| x > second}
    return next_flag ? next_flag - 1 : self.blocks - 1
  end

  nil
end
increase_by_second(second, inc = 1) click to toggle source

更新评论数

# File lib/ting_model/track_block_origin.rb, line 39
def increase_by_second(second, inc = 1)
  idx = self.get_block_idx_by_second(second)
  if idx
    col = "b#{idx}"
    count = self.send(col) + inc
    self.update_attributes(col.to_sym => (count >= 0 ? count : 0))
  end
end