Class: Tolk::Translation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tolk::Translation
- Defined in:
- app/models/tolk/translation.rb
Instance Attribute Summary collapse
-
#explicit_nil ⇒ Object
Returns the value of attribute explicit_nil.
-
#force_set_primary_update ⇒ Object
Returns the value of attribute force_set_primary_update.
-
#primary ⇒ Object
Returns the value of attribute primary.
Class Method Summary collapse
Instance Method Summary collapse
- #out_of_date? ⇒ Boolean
- #primary_translation ⇒ Object
- #text=(value) ⇒ Object
- #up_to_date? ⇒ Boolean
- #value ⇒ Object
- #variables ⇒ Object
- #variables_match? ⇒ Boolean
Instance Attribute Details
#explicit_nil ⇒ Object
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_update ⇒ Object
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 |
#primary ⇒ Object
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
34 35 36 |
# File 'app/models/tolk/translation.rb', line 34 def out_of_date? primary_updated? end |
#primary_translation ⇒ Object
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
30 31 32 |
# File 'app/models/tolk/translation.rb', line 30 def up_to_date? not out_of_date? end |
#value ⇒ Object
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 |
#variables ⇒ Object
68 69 70 |
# File 'app/models/tolk/translation.rb', line 68 def variables self.class.detect_variables(text) end |
#variables_match? ⇒ Boolean
72 73 74 |
# File 'app/models/tolk/translation.rb', line 72 def variables_match? self.variables == primary_translation.variables end |