Class: Dina::MultilingualTitle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MultilingualTitle

Returns a new instance of MultilingualTitle.



5
6
7
8
9
10
11
12
# File 'lib/dina/casters/multilingual_title.rb', line 5

def initialize(opts = {})
  @titles = []
  if opts[:titles]
    @titles = opts[:titles]
  else
    self.set_title(opts)
  end
end

Instance Attribute Details

#titlesObject

Returns the value of attribute titles.



3
4
5
# File 'lib/dina/casters/multilingual_title.rb', line 3

def titles
  @titles
end

Instance Method Details

#set_title(opts = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/dina/casters/multilingual_title.rb', line 14

def set_title(opts ={})
  opts.each do |key, value|
    titles.delete_if{|o| o[:lang] == key.to_s}
    titles << { lang: key.to_s, title: value }
  end
end

#to_hashObject



21
22
23
24
25
# File 'lib/dina/casters/multilingual_title.rb', line 21

def to_hash
  hash = {}
  instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
  hash
end