Class: Traco::LocalizedReader

Inherits:
Object
  • Object
show all
Defined in:
lib/traco/localized_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(record, attribute, options) ⇒ LocalizedReader

Returns a new instance of LocalizedReader.



3
4
5
6
7
# File 'lib/traco/localized_reader.rb', line 3

def initialize(record, attribute, options)
  @record = record
  @attribute = attribute
  @fallback = options[:fallback]
end

Instance Method Details

#valueObject



9
10
11
12
13
14
15
16
# File 'lib/traco/localized_reader.rb', line 9

def value
  locales_to_try.each do |locale|
    value = @record.send("#{@attribute}_#{Traco.locale_suffix(locale)}")
    return value if value.present?
  end

  nil
end