Class: Traco::LocalizedReader
- Inherits:
-
Object
- Object
- Traco::LocalizedReader
- Defined in:
- lib/traco/localized_reader.rb
Constant Summary collapse
- FALLBACK_OPTIONS =
[ DEFAULT_FALLBACK = :default, ANY_FALLBACK = :any, NO_FALLBACK = false, ]
Instance Method Summary collapse
-
#initialize(record, attribute, options) ⇒ LocalizedReader
constructor
A new instance of LocalizedReader.
- #value ⇒ Object
Constructor Details
#initialize(record, attribute, options) ⇒ LocalizedReader
Returns a new instance of LocalizedReader.
9 10 11 12 13 14 |
# File 'lib/traco/localized_reader.rb', line 9 def initialize(record, attribute, ) @record = record @attribute = attribute @fallback = [:fallback] validate_fallback end |
Instance Method Details
#value ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/traco/localized_reader.rb', line 16 def value locales_to_try.each do |locale| value = @record.send("#{@attribute}_#{Traco.locale_suffix(locale)}") return value if value.present? end nil end |