Class: Dina::MultilingualDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/dina/casters/multilingual_description.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionsObject

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_hashObject



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