class Babelish::CSV2Android
Attributes
file_path[RW]
Public Class Methods
new(filename, langs, args = {})
click to toggle source
Calls superclass method
# 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
Public Instance Methods
extension()
click to toggle source
# File lib/babelish/csv2android.rb, line 49 def extension "xml" end
get_row_format(row_key, row_value, comment = nil, indentation = 0)
click to toggle source
# File lib/babelish/csv2android.rb, line 30 def get_row_format(row_key, row_value, comment = nil, indentation = 0) entry = comment.to_s.empty? ? "" : "\n\t<!-- #{comment} -->\n" entry + "\t<string name=\"#{row_key}\">#{row_value}</string>\n" end
hash_to_output(content = {})
click to toggle source
# File lib/babelish/csv2android.rb, line 35 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| comment = @comments[key] output += get_row_format(key, value, comment) end output += "</resources>\n" end return output end
language_filepaths(language)
click to toggle source
# 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? filepath = Pathname.new(@file_path) + "values-#{language.code}" + output_name return filepath ? [filepath] : [] end
process_value(row_value, default_value)
click to toggle source
Calls superclass method
# File lib/babelish/csv2android.rb, line 20 def process_value(row_value, default_value) value = super(row_value, default_value) # if the value begins and ends with a quote we must leave them unescapted 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