Class: ThatLanguage::Detect
- Inherits:
-
Object
- Object
- ThatLanguage::Detect
- Defined in:
- lib/that_language/detect.rb
Constant Summary collapse
- WORD_REGEX =
/(\p{Word}+)/
- START_WITH_DIGIT_REGEX =
/^\d.*/
Instance Attribute Summary collapse
-
#lookup_context ⇒ Object
readonly
Returns the value of attribute lookup_context.
Instance Method Summary collapse
- #details(text) ⇒ Object
- #detect(text) ⇒ Object
-
#initialize(lookup_context) ⇒ Detect
constructor
A new instance of Detect.
- #language(text) ⇒ Object
- #language_code(text) ⇒ Object
Constructor Details
#initialize(lookup_context) ⇒ Detect
Returns a new instance of Detect.
8 9 10 |
# File 'lib/that_language/detect.rb', line 8 def initialize(lookup_context) @lookup_context = lookup_context end |
Instance Attribute Details
#lookup_context ⇒ Object (readonly)
Returns the value of attribute lookup_context.
6 7 8 |
# File 'lib/that_language/detect.rb', line 6 def lookup_context @lookup_context end |
Instance Method Details
#details(text) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/that_language/detect.rb', line 24 def details(text) words = words_for(text) result_set = ResultSet.new(words.length) words.each do |word| word_result = lookup_context.normalized(word) word_result.each do |language_code, value| next unless value > 0 result_set.for(language_code).add(value) end end result_set end |
#detect(text) ⇒ Object
20 21 22 |
# File 'lib/that_language/detect.rb', line 20 def detect(text) details(text).winner end |
#language(text) ⇒ Object
12 13 14 |
# File 'lib/that_language/detect.rb', line 12 def language(text) detect(text).language end |
#language_code(text) ⇒ Object
16 17 18 |
# File 'lib/that_language/detect.rb', line 16 def language_code(text) detect(text).language_code end |