Class: Translation
- Inherits:
-
String
- Object
- String
- Translation
- Defined in:
- lib/mongomapper_ext/types/translation.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
Returns the value of attribute keys.
Class Method Summary collapse
Instance Method Summary collapse
- #[](lang) ⇒ Object
- #[]=(lang, text) ⇒ Object
- #default_language=(lang) ⇒ Object
-
#initialize(*args) ⇒ Translation
constructor
A new instance of Translation.
- #languages ⇒ Object
Constructor Details
#initialize(*args) ⇒ Translation
Returns a new instance of Translation.
4 5 6 7 8 |
# File 'lib/mongomapper_ext/types/translation.rb', line 4 def initialize(*args) super @keys = {} @keys["default"] = "en" end |
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
2 3 4 |
# File 'lib/mongomapper_ext/types/translation.rb', line 2 def keys @keys end |
Class Method Details
.build(keys, default = "en") ⇒ Object
29 30 31 32 33 34 |
# File 'lib/mongomapper_ext/types/translation.rb', line 29 def self.build(keys, default = "en") tr = self.new tr.keys = keys tr.default_language = default tr end |
.from_mongo(value) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/mongomapper_ext/types/translation.rb', line 42 def self.from_mongo(value) return value if value.kind_of?(self) result = self.new result.keys = value result.default_language = value["default"] || "en" result end |
.to_mongo(value) ⇒ Object
36 37 38 39 40 |
# File 'lib/mongomapper_ext/types/translation.rb', line 36 def self.to_mongo(value) return value.keys if value.kind_of?(self) @keys end |
Instance Method Details
#[](lang) ⇒ Object
14 15 16 |
# File 'lib/mongomapper_ext/types/translation.rb', line 14 def [](lang) @keys[lang.to_s] end |
#[]=(lang, text) ⇒ Object
10 11 12 |
# File 'lib/mongomapper_ext/types/translation.rb', line 10 def []=(lang, text) @keys[lang.to_s] = text end |
#default_language=(lang) ⇒ Object
24 25 26 27 |
# File 'lib/mongomapper_ext/types/translation.rb', line 24 def default_language=(lang) @keys["default"] = lang self.replace(@keys[lang.to_s]) end |
#languages ⇒ Object
18 19 20 21 22 |
# File 'lib/mongomapper_ext/types/translation.rb', line 18 def languages langs = @keys.keys langs.delete("default") langs end |