Class: BetterTranslate::Strategies::StrategySelector

Inherits:
Object
  • Object
show all
Defined in:
lib/better_translate/strategies/strategy_selector.rb

Overview

Selects the appropriate translation strategy based on content size

Examples:

strategy = StrategySelector.select(25, config, provider, tracker)
#=> #<DeepStrategy>

strategy = StrategySelector.select(100, config, provider, tracker)
#=> #<BatchStrategy>

Constant Summary collapse

DEEP_STRATEGY_THRESHOLD =

Threshold for switching from deep to batch strategy

50

Class Method Summary collapse

Class Method Details

.select(strings_count, config, provider, progress_tracker) ⇒ BaseStrategy

Select the appropriate strategy

Examples:

Small file (deep strategy)

strategy = StrategySelector.select(30, config, provider, tracker)
#=> #<DeepStrategy>

Large file (batch strategy)

strategy = StrategySelector.select(200, config, provider, tracker)
#=> #<BatchStrategy>

Parameters:

Returns:



34
35
36
37
38
39
40
# File 'lib/better_translate/strategies/strategy_selector.rb', line 34

def self.select(strings_count, config, provider, progress_tracker)
  if strings_count < DEEP_STRATEGY_THRESHOLD
    DeepStrategy.new(config, provider, progress_tracker)
  else
    BatchStrategy.new(config, provider, progress_tracker)
  end
end