Class: Babelish::Base2Csv
- Inherits:
-
Object
- Object
- Babelish::Base2Csv
- Defined in:
- lib/babelish/base2csv.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#csv_filename ⇒ Object
Returns the value of attribute csv_filename.
-
#default_lang ⇒ Object
Returns the value of attribute default_lang.
-
#filenames ⇒ Object
Returns the value of attribute filenames.
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
-
#convert(write_to_file = true) ⇒ Hash
Process files and create csv.
-
#initialize(args = {:filenames => []}) ⇒ Base2Csv
constructor
A new instance of Base2Csv.
Constructor Details
#initialize(args = {:filenames => []}) ⇒ Base2Csv
Returns a new instance of Base2Csv.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/babelish/base2csv.rb', line 5 def initialize(args = {:filenames => []}) raise ArgumentError.new("No filenames given") unless args[:filenames] if args[:headers] raise ArgumentError.new("number of headers and files don't match, don't forget the constant column") unless args[:headers].size == (args[:filenames].size + 1) end @filenames = args[:filenames] @csv_filename = args[:csv_filename] || "translations.csv" @default_lang = args[:default_lang] @headers = args[:headers] || default_headers end |
Instance Attribute Details
#csv_filename ⇒ Object
Returns the value of attribute csv_filename.
3 4 5 |
# File 'lib/babelish/base2csv.rb', line 3 def csv_filename @csv_filename end |
#default_lang ⇒ Object
Returns the value of attribute default_lang.
3 4 5 |
# File 'lib/babelish/base2csv.rb', line 3 def default_lang @default_lang end |
#filenames ⇒ Object
Returns the value of attribute filenames.
3 4 5 |
# File 'lib/babelish/base2csv.rb', line 3 def filenames @filenames end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/babelish/base2csv.rb', line 3 def headers @headers end |
Instance Method Details
#convert(write_to_file = true) ⇒ Hash
Process files and create csv
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/babelish/base2csv.rb', line 24 def convert(write_to_file = true) strings = {} keys = nil comments = {} @filenames.each do |fname| header = fname strings[header], file_comments = load_strings(fname) keys ||= strings[header].keys comments.merge!(file_comments) end if write_to_file # Create csv file puts "Creating #{@csv_filename}" create_csv_file(keys, strings, comments) else return keys, strings end end |