Class: Enop::Dbutil::EnopMgr
- Inherits:
-
Object
- Object
- Enop::Dbutil::EnopMgr
- Extended by:
- Forwardable
- Defined in:
- lib/enop/dbutil/enopmgr.rb
Instance Method Summary collapse
- #add(stack, notebook, count, tag_count) ⇒ Object
-
#initialize(register_time) ⇒ EnopMgr
constructor
A new instance of EnopMgr.
- #post_process(dir_id) ⇒ Object
Constructor Details
#initialize(register_time) ⇒ EnopMgr
Returns a new instance of EnopMgr.
27 28 29 30 31 32 |
# File 'lib/enop/dbutil/enopmgr.rb', line 27 def initialize(register_time) @register_time = register_time @ct = Countdatetime.create( countdatetime: @register_time ) @hs_by_notebook = {} @hs_by_id = {} end |
Instance Method Details
#add(stack, notebook, count, tag_count) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/enop/dbutil/enopmgr.rb', line 34 def add( stack , notebook, count, tag_count ) ennblist = @hs_by_notebook[notebook] unless ennblist cur_ennblist = Currentennblist.where( notebook: notebook ).limit(1) if cur_ennblist.size == 0 begin ennblist = Ennblist.create( stack: stack, notebook: notebook , count: count, tag_count: tag_count , start_datetime: @register_time ) evnb = Evnb.create( time_id: @ct.id , ennb_id: ennblist.id ) rescue => ex p ex.class p ex. pp ex.backtrace ennblist = nil evnb = nil end else current_ennblist = cur_ennblist.first.ennblist hs = {:stack => stack, :count => count , :tag_count => tag_count } value_hs = hs.reduce({}){ |hsx,item| if current_ennblist[ item[0] ] != item[1] hsx[ item[0] ] = item[1] end hsx } if value_hs.size > 0 if value_hs.all? { |item| item[1] != nil } current_ennblist.update(value_hs) end end end else # ignore this case. end if ennblist @hs_by_notebook[notebook] = ennblist @hs_by_id[ennblist.id] = ennblist end ennblist end |
#post_process(dir_id) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/enop/dbutil/enopmgr.rb', line 76 def post_process( dir_id ) h_ids = Currentennblist.pluck(:org_id) t_ids = @hs_by_id.keys ids = h_ids - t_ids if ids.size > 0 ids.each do |idx| Invalidennblist.create( org_id: idx , end_datetime: @register_time ) end end end |