Class: NewsScraper::Trainer::PresetSelector
- Inherits:
-
Object
- Object
- NewsScraper::Trainer::PresetSelector
- Defined in:
- lib/news_scraper/trainer/preset_selector.rb
Constant Summary collapse
- PROVIDER_PHRASE =
'I will provide a pattern using'.freeze
Instance Method Summary collapse
-
#initialize(url:, payload:) ⇒ PresetSelector
constructor
A new instance of PresetSelector.
- #select(data_type) ⇒ Object
Constructor Details
#initialize(url:, payload:) ⇒ PresetSelector
Returns a new instance of PresetSelector.
6 7 8 9 |
# File 'lib/news_scraper/trainer/preset_selector.rb', line 6 def initialize(url:, payload:) @url = url @payload = payload end |
Instance Method Details
#select(data_type) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/news_scraper/trainer/preset_selector.rb', line 11 def select(data_type) = (data_type) selected_option = CLI.( "Select which preset to use for #{data_type}:", .keys ) if selected_option.start_with?(PROVIDER_PHRASE) pattern_type = [selected_option] return { 'method' => pattern_type, 'pattern' => CLI.get_input("Provide the #{pattern_type} pattern:") } end return if selected_option == 'skip' selected_preset_code = [selected_option] result = transform_results[data_type][selected_preset_code].merge( 'variable' => [selected_preset_code, data_type].join('_') ) result.delete('data') result end |