Class: Translatomatic::ResourceFile::CSV

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/resource_file/csv.rb

Overview

CSV resource file

Instance Attribute Summary

Attributes inherited from Base

#locale, #options, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#create_variable, enabled?, #get, #get_context, #initialize, key_value?, #locale_path, preferred_locale_separator, #properties, #properties=, #sentences, supports_variable_interpolation?, #to_s, #type, #variable_regex

Methods included from PathUtils

#detect_path_locale, #modify_path_locale

Constructor Details

This class inherits a constructor from Translatomatic::ResourceFile::Base

Class Method Details

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



8
9
10
# File 'lib/translatomatic/resource_file/csv.rb', line 8

def self.extensions
  %w[csv]
end

Instance Method Details

#save(target = path, options = {}) ⇒ void

This method returns an undefined value.

Save the resource file.

Parameters:

  • target (Pathname) (defaults to: path)

    The destination path

  • options (Hash<Symbol, Object>) (defaults to: {})

    Output format options



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/translatomatic/resource_file/csv.rb', line 23

def save(target = path, options = {})
  use_headers = @options[:csv_headers]
  csv_options = { write_headers: use_headers }
  csv_options[:headers] = @headers if use_headers

  ::CSV.open(target, 'wb', csv_options) do |csv|
    @rows.each do |row|
      csv << row.collect(&:value)
    end
  end
end

#set(key, value) ⇒ String

Set a property

Parameters:

  • key (String)

    The name of the property

  • value (String)

    The new value of the property

Returns:

  • (String)

    The new value of the property



13
14
15
16
17
18
19
20
# File 'lib/translatomatic/resource_file/csv.rb', line 13

def set(key, value)
  super(key, value)
  if @cellmap.include?(key)
    @cellmap[key].value = value
  else
    add_row(key, value)
  end
end