Class: Andromeda::Kit::FileChunker

Inherits:
FileReader show all
Defined in:
lib/andromeda/kit.rb

Instance Attribute Summary collapse

Attributes inherited from FileReader

#mode, #path

Attributes inherited from Plan

#error_level, #log, #marker, #nick, #trace_enter, #trace_exit

Attributes inherited from Impl::ProtoPlan

#guide, #id

Instance Method Summary collapse

Methods inherited from FileReader

#data_tag, #init_mode

Methods inherited from Plan

#initialize_copy, #pool, #tap, #to_short_s

Methods inherited from Impl::ProtoPlan

#>>, #current_name, #current_scope, #data_key, #data_tag, #data_val, #dest, #entry, #init_guide, #initialize_copy, #key_label, #key_spot, #map_data, #mute, name_spot, #post_data, #post_to, #public_spot, #selects?, #signal_name?, signal_names, #signal_names, signal_spot, spot_attr, #spot_attr_name?, spot_attr_names, #spot_attr_names, spot_meth, #spot_meth_name?, #spot_meth_names, spot_meth_names, #spot_name?, spot_names, #spot_names, #tags, #to_short_s, #via

Methods included from Impl::To_S

short_s, #to_s, #to_short_s

Methods inherited from Impl::ConnectorBase

#post, #post_local, #start

Constructor Details

#initialize(config = {}) ⇒ FileChunker

Returns a new instance of FileChunker.



169
170
171
172
# File 'lib/andromeda/kit.rb', line 169

def initialize(config = {})
  super config
  @num_chunks ||= Guides::PoolGuide.num_procs
end

Instance Attribute Details

#num_chunksObject (readonly)

Returns the value of attribute num_chunks.



167
168
169
# File 'lib/andromeda/kit.rb', line 167

def num_chunks
  @num_chunks
end

Instance Method Details

#on_enter(key, val) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/andromeda/kit.rb', line 174

def on_enter(key, val)
  num_c = num_chunks
  super key, val do |f|
    fst = tags[:first]
    lst = tags[:last]
    sz  = tags[:num] / num_c rescue 1
    sz  = 1 if sz < 0
    while fst <= lst
      nxt = fst + sz
      nxt = lst if nxt > lst
      exit << Range.new(fst, nxt)
      fst = nxt + 1
    end
  end
end