class Commandline
Constants
- BASECLASSES
- CSVCLASSES
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/babelish/commandline.rb, line 176 def self.exit_on_failure? true end
Public Instance Methods
base2csv(classname)
click to toggle source
# File lib/babelish/commandline.rb, line 167 def base2csv(classname) class_object = eval "Babelish::#{classname}" converter = class_object.new(options) debug_values = converter.convert(!options[:dryrun]) say debug_values.inspect if options[:dryrun] end
csv2base(classname)
click to toggle source
# File lib/babelish/commandline.rb, line 136 def csv2base(classname) args = options.dup if options[:fetch] say "Fetching csv file #{options[:filename]} from Google Drive" files = download(options[:filename], nil, options[:sheet]) abort if files.empty? # no file downloaded args.delete(:fetch) else files = [options[:filename]] end args.delete(:langs) args.delete(:filename) xcode_macros = Babelish::XcodeMacros.new if options[:macros_filename] files.each_with_index do |filename, index| if options[:output_basenames] args[:output_basename] = options[:output_basenames][index] end class_object = eval "Babelish::#{classname}" args = Thor::CoreExt::HashWithIndifferentAccess.new(args) converter = class_object.new(filename, options[:langs], args) say converter.convert xcode_macros.process(converter.table, converter.keys, converter.comments) if options[:macros_filename] end if options[:macros_filename] say "generating macros" xcode_macros.write_content(options[:macros_filename]) end end
csv_download()
click to toggle source
# File lib/babelish/commandline.rb, line 71 def csv_download all = options[:sheet] ? false : options[:all] filename = options['gd_filename'] raise ArgumentError.new("csv_download command : missing file to download") unless filename if all download(filename) else download(filename, options['output_filename'], options['sheet']) end end
download(filename, output_filename = nil, worksheet_index = nil)
click to toggle source
# File lib/babelish/commandline.rb, line 118 def download(filename, output_filename = nil, worksheet_index = nil) gd = Babelish::GoogleDoc.new if output_filename || worksheet_index file_path = gd.download_spreadsheet filename.to_s, output_filename, worksheet_index files = [file_path].compact else files = gd.download filename.to_s file_path = files.join("\n") unless files.empty? end if file_path say "File '#{filename}' downloaded to :\n#{file_path.to_s}" else say "Could not download the requested file: #{filename}" end files end
init()
click to toggle source
# File lib/babelish/commandline.rb, line 96 def init if File.exist?(".babelish") say "Config file '.babelish' already exists." else say "Creating new config file '.babelish'." config_file = File.expand_path("../../../.babelish.sample", __FILE__) if File.exist?(config_file) system "cp #{config_file} .babelish" else say "Template '#{config_file}' not found." end end end
open(file = "translations.csv")
click to toggle source
# File lib/babelish/commandline.rb, line 83 def open(file = "translations.csv") filename = file || options["filename"] if File.exist?(filename) say "Opening local file '#{filename}'" system "open \"#{filename}\"" else say "Opening Google Drive file '#{filename}'" gd = Babelish::GoogleDoc.new gd.open filename.to_s end end
version()
click to toggle source
# File lib/babelish/commandline.rb, line 112 def version require "babelish/version" say "Babelish #{Babelish::VERSION}" end
Private Instance Methods
options()
click to toggle source
Calls superclass method
# File lib/babelish/commandline.rb, line 182 def options original_options = super return original_options unless File.exist?(original_options["config"]) defaults = ::YAML.load_file(original_options["config"]) || {} Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options)) end