Module: Rack::ICU4X::Locale::Detector

Defined in:
lib/rack/icu4x/locale/detector.rb,
lib/rack/icu4x/locale/detector/query.rb,
lib/rack/icu4x/locale/detector/cookie.rb,
lib/rack/icu4x/locale/detector/header.rb

Overview

Factory module for building detector instances from various specification formats.

Detectors are responsible for extracting locale preferences from the Rack environment. All detectors respond to ‘#call(env)` and return:

  • String: single locale (e.g., “ja”)

  • Array<String>: multiple locales in preference order (e.g., [“ja”, “en”])

  • nil: no locale detected

Examples:

Building detectors from different specification formats

Detector.build(:header)                    # => Detector::Header.new
Detector.build({ cookie: "locale" })       # => Detector::Cookie.new("locale")
Detector.build(->(env) { "ja" })           # => the Proc itself

Defined Under Namespace

Classes: Cookie, Header, InvalidSpecificationError, Query

Class Method Summary collapse

Class Method Details

.build(spec) ⇒ #call

Build a detector from various specification formats.

Parameters:

  • spec (Symbol, Hash, Proc, #call)

    Detector specification

Returns:

  • (#call)

    Detector instance responding to #call(env)

Raises:



29
30
31
32
33
34
35
36
37
38
# File 'lib/rack/icu4x/locale/detector.rb', line 29

def self.build(spec)
  case spec
  when Symbol then build_from_symbol(spec)
  when Hash then build_from_hash(spec)
  when Proc then spec
  else
    validate_callable!(spec)
    spec
  end
end