class Array

Public Instance Methods

tml_translated() click to toggle source
# File lib/tml/ext/array.rb, line 87
def tml_translated
  return self if frozen?
  @tml_translated = true
  self
end
tml_translated?() click to toggle source
# File lib/tml/ext/array.rb, line 93
def tml_translated?
  @tml_translated
end
translate(description = '', options = {}) click to toggle source

translate array values

# File lib/tml/ext/array.rb, line 58
def translate(description = '', options = {})
  return [] if empty?

  collect do |opt|
    if opt.is_a?(String)
      opt.translate(description, {}, options)
    else  
      opt
    end
  end
end
translate_and_join(separator = ', ', description = '', options = {}) click to toggle source

translates and joins all elements

# File lib/tml/ext/array.rb, line 53
def translate_and_join(separator = ', ', description = '', options = {})
  self.translate(description, options).join(separator).tml_translated
end
translate_options(description = '', options = {}) click to toggle source

translates an array of options for a select tag

# File lib/tml/ext/array.rb, line 35
def translate_options(description = '', options = {})
  return [] if empty?

  options = options.merge(:skip_decorations => true)

  collect do |opt|
    if opt.is_a?(Array) and opt.first.is_a?(String) 
      [opt.first.translate(description, {}, options), opt.last]
    elsif opt.is_a?(String)
      [opt.translate(description, {}, options), opt]
    else  
      opt
    end
  end
end
Also aliased as: tro
translate_sentence(description = nil, options = {}) click to toggle source

creates a sentence with tr “and” joiner

# File lib/tml/ext/array.rb, line 71
def translate_sentence(description = nil, options = {})
  return '' if empty?
  return first if size == 1

  elements = translate(description, options)

  options[:separator] ||= ', '
  options[:joiner] ||= 'and'

  result = elements[0..-2].join(options[:separator])
  result << ' ' << options[:joiner].translate(description || 'List elements joiner', {}, options) << ' '
  result << elements.last

  result.tml_translated
end
tro(description = '', options = {})
Alias for: translate_options