Class: Mongoid::Verbalize::TranslatedString::LocalizedValue

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/verbalize/translated_string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_value = nil, versions = []) ⇒ LocalizedValue

Returns a new instance of LocalizedValue.



12
13
14
15
# File 'lib/mongoid/verbalize/translated_string.rb', line 12

def initialize(current_value=nil, versions=[])
  @current_value = current_value
  @versions = versions
end

Instance Attribute Details

#current_valueObject

Returns the value of attribute current_value.



10
11
12
# File 'lib/mongoid/verbalize/translated_string.rb', line 10

def current_value
  @current_value
end

#versionsObject

Returns the value of attribute versions.



10
11
12
# File 'lib/mongoid/verbalize/translated_string.rb', line 10

def versions
  @versions
end

Instance Method Details

#add_version(new_version_number) ⇒ Object



22
23
24
# File 'lib/mongoid/verbalize/translated_string.rb', line 22

def add_version(new_version_number)
  versions.push(LocalizedVersion.new(new_version_number, current_value))
end

#changed?Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/mongoid/verbalize/translated_string.rb', line 17

def changed?
  previous_version = versions.last
  previous_version.nil? || previous_version.value != current_value
end

#find_version(version) ⇒ Object



26
27
28
# File 'lib/mongoid/verbalize/translated_string.rb', line 26

def find_version(version)
  versions.find_all { |v| v.version <= version }.last
end