Class: VibeSort::Client
- Inherits:
-
Object
- Object
- VibeSort::Client
- Defined in:
- lib/vibe_sort/client.rb
Overview
Client is the main public interface for the VibeSort gem
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(api_key:, temperature: 0.0, provider: nil, model: nil, extra_params: {}) ⇒ Client
constructor
Initialize a new VibeSort client.
-
#sort(array) ⇒ Hash
Sort an array of numbers and/or strings using the configured provider's API.
Constructor Details
#initialize(api_key:, temperature: 0.0, provider: nil, model: nil, extra_params: {}) ⇒ Client
Initialize a new VibeSort client
38 39 40 41 |
# File 'lib/vibe_sort/client.rb', line 38 def initialize(api_key:, temperature: 0.0, provider: nil, model: nil, extra_params: {}) @config = Configuration.new(api_key: api_key, temperature: temperature, provider: provider, model: model, extra_params: extra_params) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/vibe_sort/client.rb', line 6 def config @config end |
Instance Method Details
#sort(array) ⇒ Hash
Sort an array of numbers and/or strings using the configured provider's API
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vibe_sort/client.rb', line 71 def sort(array) # Validate input unless valid_input?(array) return { success: false, sorted_array: [], error: "Input must be an array of numbers or strings" } end # Perform the sort via API sorter = Sorter.new(config) sorter.perform(array) rescue ApiError => e { success: false, sorted_array: [], error: e. } rescue StandardError => e { success: false, sorted_array: [], error: "Unexpected error: #{e.}" } end |