Class: Foxtail::Sequence
- Inherits:
-
Object
- Object
- Foxtail::Sequence
- Defined in:
- lib/foxtail/sequence.rb
Overview
Manages ordered sequences of Bundles for language fallback.
Instance Method Summary collapse
-
#find(*ids) ⇒ Bundle, ...
Finds the first bundle that contains a message with the given ID(s).
-
#format(id, errors = nil) ⇒ String
Formats a message using the first bundle that contains it.
-
#initialize(*bundles) ⇒ Sequence
constructor
Creates a new Sequence with the given bundles.
Constructor Details
#initialize(*bundles) ⇒ Sequence
Creates a new Sequence with the given bundles.
19 20 21 |
# File 'lib/foxtail/sequence.rb', line 19 def initialize(*bundles) @bundles = bundles.flatten.freeze end |
Instance Method Details
#find(*ids) ⇒ Bundle, ...
Finds the first bundle that contains a message with the given ID(s).
28 29 30 31 32 33 34 |
# File 'lib/foxtail/sequence.rb', line 28 def find(*ids) if ids.size == 1 find_bundle(ids.first) else ids.map {|id| find_bundle(id) } end end |
#format(id, errors = nil) ⇒ String
Formats a message using the first bundle that contains it. Keyword arguments are passed through to the bundle’s format method.
42 43 44 45 |
# File 'lib/foxtail/sequence.rb', line 42 def format(id, errors=nil, **) bundle = find_bundle(id) bundle ? bundle.format(id, errors, **) : id.to_s end |