Class: Translation

Inherits:
Object
  • Object
show all
Defined in:
lib/linguara/translation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, options = {}) ⇒ Translation



5
6
7
8
9
10
11
12
13
# File 'lib/linguara/translation.rb', line 5

def initialize(element,options = {})
  options[:translation] ||= {}
  options[:translation][:due_date] ||= Date.today + Linguara.configuration.request_valid_for.to_i.days unless Linguara.configuration.request_valid_for.blank?
  options[:translation][:due_date] ||= Date.today + 1.month
  options[:return_url] ||= Linguara.configuration.return_url
  options[:source_language] ||= I18n.locale.to_s
  self.element = element#.fields_to_send
  self.translation_hash = options
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



3
4
5
# File 'lib/linguara/translation.rb', line 3

def element
  @element
end

#translation_hashObject

Returns the value of attribute translation_hash.



3
4
5
# File 'lib/linguara/translation.rb', line 3

def translation_hash
  @translation_hash
end

Instance Method Details

#to_hashObject



15
16
17
18
19
# File 'lib/linguara/translation.rb', line 15

def to_hash
  ret = {}
  ret[:request] = self.translation_hash
  ret
end

#to_xml(options = {}, builder_options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/linguara/translation.rb', line 21

def to_xml(options = {}, builder_options = {})
  builder_options[:indent] ||= 2
  xml = builder_options[:builder] ||= Builder::XmlMarkup.new(:indent => builder_options[:indent])
  xml.instruct! unless builder_options[:skip_instruct]
  xml.request do
    self.translation_hash.merge(options).each_pair do |k, v|
      next if k.blank? or v.blank?
      tag_element(xml, k, v)
    end
    xml.content :type => 'html' do
      self.element.fields_to_send.each_pair do |k, v|
        xml.paragraph(:id => k) {|x| x << v}
      end
    end
  end
end