Sha256: f2fb816d296ba1a2cd9d06f68324bf0cc8b74f9d9b514608c1ce0c03711ea98f

Contents?: true

Size: 974 Bytes

Versions: 15

Compression:

Stored size: 974 Bytes

Contents

module Tongues
  module Detection
    require 'tongues/api_connexion'
    require 'tongues/config/configuration'

    ## Returns the full language name
    def tongue
      detect_tongue && detect_tongue.language
    end

    ## Returns the language code
    def tongue_code
      detect_tongue && detect_tongue.lang_symbol
    end

    ## Returns the confidence in language
    def tongue_confidence
      detect_tongue && detect_tongue.confidence
    end

    ## Comparison to languages
    Tongues::Configuration.languages.each do |lang_symbol, language|
      self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{lang_symbol}?
          language && language == "#{lang_symbol}"
        end

        def #{language}?
          full_language && full_language == "#{language}"
        end
      RUBY
    end

    private

    ## Calls the api and returns the language
    def detect_tongue
      @tongue ||= Tongues::ApiConnexion.detect self.to_s
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tongues-0.1.1 lib/tongues/core_ext/detection.rb
tongues-0.1.0 lib/tongues/core_ext/detection.rb
tongues-0.0.13 lib/tongues/core_ext/detection.rb
tongues-0.0.12 lib/tongues/core_ext/detection.rb
tongues-0.0.11 lib/tongues/core_ext/detection.rb
tongues-0.0.10 lib/tongues/core_ext/detection.rb
tongues-0.0.9 lib/tongues/core_ext/detection.rb
tongues-0.0.8 lib/tongues/core_ext/detection.rb
tongues-0.0.7 lib/tongues/core_ext/detection.rb
tongues-0.0.6 lib/tongues/core_ext/detection.rb
tongues-0.0.5 lib/tongues/core_ext/detection.rb
tongues-0.0.4 lib/tongues/core_ext/detection.rb
tongues-0.0.3 lib/tongues/core_ext/detection.rb
tongues-0.0.2 lib/tongues/core_ext/detection.rb
tongues-0.0.1 lib/tongues/core_ext/detection.rb