Class: TrackBlockOrigin

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
TrackBlockExtender
Defined in:
lib/ting_model/track_block_origin.rb

Constant Summary collapse

TRACK_MAX_BLOCKS =

播放彩条分块

30
MIN_SECONDS_PER_BLOCK =

彩条分块每块默认几秒

2

Instance Method Summary collapse

Methods included from TrackBlockExtender

next_id

Instance Method Details

#get_block_idx_by_second(second) ⇒ Object



28
29
30
31
32
33
34
35
36
# 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) ⇒ Object

更新评论数



39
40
41
42
43
44
45
46
# 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