Class: JtcgLocaleDetector::Client
- Inherits:
-
Object
- Object
- JtcgLocaleDetector::Client
- Defined in:
- lib/jtcg_locale_detector/client.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#detect(text) ⇒ Object
Detect locale for a single text.
-
#detect_batch(texts) ⇒ Object
Detect locales for multiple texts.
-
#detect_file(file_path) ⇒ Object
Detect locale from file.
-
#detect_with_details(text) ⇒ Object
Get detailed detection information.
-
#initialize(**options) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(**options) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/jtcg_locale_detector/client.rb', line 9 def initialize(**) = .merge() validate_python_environment end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/jtcg_locale_detector/client.rb', line 7 def end |
Instance Method Details
#detect(text) ⇒ Object
Detect locale for a single text
15 16 17 18 19 20 |
# File 'lib/jtcg_locale_detector/client.rb', line 15 def detect(text) return nil if text.nil? || text.strip.empty? result = execute_detection(text: text) parse_result(result) end |
#detect_batch(texts) ⇒ Object
Detect locales for multiple texts
23 24 25 26 27 |
# File 'lib/jtcg_locale_detector/client.rb', line 23 def detect_batch(texts) return [] if texts.nil? || texts.empty? texts.map { |text| detect(text) } end |
#detect_file(file_path) ⇒ Object
Detect locale from file
30 31 32 33 34 35 |
# File 'lib/jtcg_locale_detector/client.rb', line 30 def detect_file(file_path) raise Error, "File not found: #{file_path}" unless File.exist?(file_path) result = execute_detection(file: file_path) parse_result(result) end |
#detect_with_details(text) ⇒ Object
Get detailed detection information
38 39 40 41 42 43 |
# File 'lib/jtcg_locale_detector/client.rb', line 38 def detect_with_details(text) return nil if text.nil? || text.strip.empty? result = execute_detection(text: text, details: true) parse_detailed_result(result) end |