Class: Tolk::Translation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/tolk/translation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#explicit_nilObject

Returns the value of attribute explicit_nil.



27
28
29
# File 'app/models/tolk/translation.rb', line 27

def explicit_nil
  @explicit_nil
end

#force_set_primary_updateObject

Returns the value of attribute force_set_primary_update.



19
20
21
# File 'app/models/tolk/translation.rb', line 19

def force_set_primary_update
  @force_set_primary_update
end

#primaryObject

Returns the value of attribute primary.



24
25
26
# File 'app/models/tolk/translation.rb', line 24

def primary
  @primary
end

Class Method Details

.detect_variables(search_in) ⇒ Object



59
60
61
62
63
64
65
66
# File 'app/models/tolk/translation.rb', line 59

def self.detect_variables(search_in)
  case search_in
    when String then Set.new(search_in.scan(/\{\{(\w+)\}\}/).flatten + search_in.scan(/\%\{(\w+)\}/).flatten)
    when Array then search_in.inject(Set[]) { |carry, item| carry + detect_variables(item) }
    when Hash then search_in.values.inject(Set[]) { |carry, item| carry + detect_variables(item) }
    else Set[]
  end
end

Instance Method Details

#out_of_date?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/tolk/translation.rb', line 34

def out_of_date?
  primary_updated?
end

#primary_translationObject



38
39
40
41
42
43
44
# File 'app/models/tolk/translation.rb', line 38

def primary_translation
  @_primary_translation ||= begin
    if locale && !locale.primary?
      phrase.translations.primary
    end
  end
end

#text=(value) ⇒ Object



46
47
48
49
# File 'app/models/tolk/translation.rb', line 46

def text=(value)
  value = value.to_s if value.kind_of?(Fixnum)
  super unless value.to_s == text
end

#up_to_date?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/tolk/translation.rb', line 30

def up_to_date?
  not out_of_date?
end

#valueObject



51
52
53
54
55
56
57
# File 'app/models/tolk/translation.rb', line 51

def value
  if text.is_a?(String) && /^\d+$/.match(text)
    text.to_i
  else
    text
  end
end

#variablesObject



68
69
70
# File 'app/models/tolk/translation.rb', line 68

def variables
  self.class.detect_variables(text)
end

#variables_match?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/tolk/translation.rb', line 72

def variables_match?
  self.variables == primary_translation.variables
end