Class: Babelish::CSV2Android
Instance Attribute Summary collapse
Attributes inherited from Csv2Base
#comments_column, #csv_filename, #csv_separator, #default_lang, #excluded_states, #ignore_lang_path, #keys_column, #langs, #languages, #output_basename, #output_dir, #state_column
Instance Method Summary
collapse
Methods inherited from Csv2Base
#comments, #convert, #create_file_from_path, #default_filepath, #keys, #table, #write_content
Constructor Details
#initialize(filename, langs, args = {}) ⇒ CSV2Android
Returns a new instance of CSV2Android.
5
6
7
8
9
10
|
# File 'lib/babelish/csv2android.rb', line 5
def initialize(filename, langs, args = {})
super(filename, langs, args)
@file_path = args[:output_dir].to_s
@output_basename = args[:output_basename].to_s
end
|
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
3
4
5
|
# File 'lib/babelish/csv2android.rb', line 3
def file_path
@file_path
end
|
Instance Method Details
#extension ⇒ Object
50
51
52
|
# File 'lib/babelish/csv2android.rb', line 50
def extension
"xml"
end
|
31
32
33
34
|
# File 'lib/babelish/csv2android.rb', line 31
def get_row_format(row_key, row_value, = nil, indentation = 0)
entry = .to_s.empty? ? "" : "\n\t<!-- #{} -->\n"
entry + "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
end
|
#hash_to_output(content = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/babelish/csv2android.rb', line 36
def hash_to_output(content = {})
output = ''
if content && content.size > 0
output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
output += "<resources>\n"
content.each do |key, value|
= @comments[key]
output += get_row_format(key, value, )
end
output += "</resources>\n"
end
return output
end
|
#language_filepaths(language) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/babelish/csv2android.rb', line 12
def language_filepaths(language)
require 'pathname'
output_name = "strings.xml"
output_name = "#{@output_basename}.xml" unless @output_basename.empty?
region = language.region.to_s.empty? ? "" : "-r#{language.region}"
filepath = Pathname.new(@file_path) + "values-#{language.code}#{region}" + output_name
return filepath ? [filepath] : []
end
|
#process_value(row_value, default_value) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/babelish/csv2android.rb', line 21
def process_value(row_value, default_value)
value = super(row_value, default_value)
if value.size > 4 && value[0, 2] == "\\\"" && value[value.size - 2, value.size] == "\\\""
value[0, 2] = "\""
value[value.size - 2, value.size] = "\""
end
value.to_utf8
end
|