Class: Translatomatic::StringBatcher
- Inherits:
-
Object
- Object
- Translatomatic::StringBatcher
- Includes:
- Util
- Defined in:
- lib/translatomatic/string_batcher.rb
Overview
each_slice with a limit on number of strings and also an optional character limit.
Instance Method Summary collapse
-
#each_batch ⇒ Array<String>
Yields lists of strings within the size constraints given to the constructor.
-
#initialize(strings, max_count:, max_length:) ⇒ StringBatcher
constructor
A new instance of StringBatcher.
Constructor Details
#initialize(strings, max_count:, max_length:) ⇒ StringBatcher
Returns a new instance of StringBatcher.
10 11 12 13 14 15 16 |
# File 'lib/translatomatic/string_batcher.rb', line 10 def initialize(strings, max_count:, max_length:) @strings = strings @max_count = max_count @max_length = max_length @batch = [] @length = 0 end |
Instance Method Details
#each_batch ⇒ Array<String>
Yields lists of strings within the size constraints given to the constructor.
21 22 23 24 25 26 |
# File 'lib/translatomatic/string_batcher.rb', line 21 def each_batch @strings.each do |string| process_string(string) { |batch| yield batch } end yield_batch { |batch| yield batch } # send remaining strings end |