Class: Dina::MultilingualDescription
- Inherits:
-
Object
- Object
- Dina::MultilingualDescription
- Defined in:
- lib/dina/casters/multilingual_description.rb
Instance Attribute Summary collapse
-
#descriptions ⇒ Object
Returns the value of attribute descriptions.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ MultilingualDescription
constructor
A new instance of MultilingualDescription.
- #set_description(opts = {}) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ MultilingualDescription
Returns a new instance of MultilingualDescription.
5 6 7 8 9 10 11 12 |
# File 'lib/dina/casters/multilingual_description.rb', line 5 def initialize(opts = {}) @descriptions = [] if opts[:descriptions] @descriptions = opts[:descriptions] else self.set_description(opts) end end |
Instance Attribute Details
#descriptions ⇒ Object
Returns the value of attribute descriptions.
3 4 5 |
# File 'lib/dina/casters/multilingual_description.rb', line 3 def descriptions @descriptions end |
Instance Method Details
#set_description(opts = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/dina/casters/multilingual_description.rb', line 14 def set_description(opts = {}) opts.each do |key, value| descriptions.delete_if{|o| o[:lang] == key.to_s} descriptions << { lang: key.to_s, desc: value } end end |
#to_hash ⇒ Object
21 22 23 24 25 |
# File 'lib/dina/casters/multilingual_description.rb', line 21 def to_hash hash = {} instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) } hash end |