Class: FileManager
- Inherits:
-
Object
- Object
- FileManager
- Defined in:
- lib/file_manager.rb
Instance Method Summary collapse
- #create_file ⇒ Object
- #get_file_name ⇒ Object
- #get_template_path ⇒ Object
-
#initialize(language, items, output_folder, platform, dryrun = false) ⇒ FileManager
constructor
A new instance of FileManager.
- #pretty_print(path_to_file) ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(language, items, output_folder, platform, dryrun = false) ⇒ FileManager
Returns a new instance of FileManager.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/file_manager.rb', line 7 def initialize language, items, output_folder, platform, dryrun=false if language==nil puts "INTERRUPTION:\n" puts "Something is wrong with one of your language columns (maybe it's missing?)\n".red exit 1 end @language = language.downcase @platform = platform @dryrun = dryrun @items = items @path = output_folder @template = File.read(get_template_path) end |
Instance Method Details
#create_file ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/file_manager.rb', line 35 def create_file file_name = get_file_name destination_file_path = "#{@path}#{file_name}" pretty_print destination_file_path unless @dryrun dirname = File.dirname(destination_file_path) unless File.directory?(dirname) FileUtils.mkdir_p(dirname) end File.open(destination_file_path, 'w') { |f| f.write(render) } else puts render.yellow end end |
#get_file_name ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/file_manager.rb', line 27 def get_file_name if @platform.eql?'android' "values-#{@language}/translation.xml" else "#{@language}.lbproj/Localizable.strings" end end |
#get_template_path ⇒ Object
23 24 25 |
# File 'lib/file_manager.rb', line 23 def get_template_path File.join(File.dirname(__FILE__), "templates/#{@platform}.erb") end |
#pretty_print(path_to_file) ⇒ Object
53 54 55 56 |
# File 'lib/file_manager.rb', line 53 def pretty_print(path_to_file) subtracted = path_to_file.gsub("#{Dir.pwd}/",'') puts "created #{subtracted.green} successfully" end |
#render ⇒ Object
58 59 60 |
# File 'lib/file_manager.rb', line 58 def render ERB.new(@template).result(binding) end |