Class: RText::DefaultLoader::ProgressMonitor
- Inherits:
-
Object
- Object
- RText::DefaultLoader::ProgressMonitor
- Defined in:
- lib/rtext/default_loader.rb
Instance Method Summary collapse
- #after_fragment_load(frag) ⇒ Object
- #before_fragment_load(frag, kind) ⇒ Object
-
#initialize(on_progress_proc, files) ⇒ ProgressMonitor
constructor
A new instance of ProgressMonitor.
- #instantiator_progress(frag, steps) ⇒ Object
Constructor Details
#initialize(on_progress_proc, files) ⇒ ProgressMonitor
Returns a new instance of ProgressMonitor.
98 99 100 101 102 103 104 |
# File 'lib/rtext/default_loader.rb', line 98 def initialize(on_progress_proc, files) @on_progress_proc = on_progress_proc || lambda {|frag, work_done, work_overall| } # there is a progress call twice for each element (in tokenizer and instantiator) @work_overall = num_elements(files)*2 @work_done = 0 @work_last_sent = 0 end |
Instance Method Details
#after_fragment_load(frag) ⇒ Object
110 111 112 113 114 |
# File 'lib/rtext/default_loader.rb', line 110 def after_fragment_load(frag) @work_done += frag.elements.size*2 if @loading_cached @on_progress_proc.call(frag, @work_done, @work_overall) @work_last_sent = @work_done end |
#before_fragment_load(frag, kind) ⇒ Object
106 107 108 |
# File 'lib/rtext/default_loader.rb', line 106 def before_fragment_load(frag, kind) @loading_cached = (kind == :load_cached) end |
#instantiator_progress(frag, steps) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/rtext/default_loader.rb', line 116 def instantiator_progress(frag, steps) @work_done += steps if @work_done > @work_last_sent + 100 @on_progress_proc.call(frag, @work_done, @work_overall) @work_last_sent = @work_done end end |