Class: Babelish::Php2CSV
Instance Attribute Summary
Attributes inherited from Base2Csv
#csv_filename, #default_lang, #filenames, #headers
Instance Method Summary collapse
-
#initialize(args = {:filenames => []}) ⇒ Php2CSV
constructor
A new instance of Php2CSV.
- #load_strings(strings_filename) ⇒ Object
- #parse_dotstrings_line(line) ⇒ Object
Methods inherited from Base2Csv
Constructor Details
#initialize(args = {:filenames => []}) ⇒ Php2CSV
Returns a new instance of Php2CSV.
4 5 6 |
# File 'lib/babelish/php2csv.rb', line 4 def initialize(args = {:filenames => []}) super(args) end |
Instance Method Details
#load_strings(strings_filename) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/babelish/php2csv.rb', line 8 def load_strings(strings_filename) strings = {} File.open(strings_filename, 'r') do |strings_file| strings_file.read.each_line do |line| parsed_line = parse_dotstrings_line(line) unless parsed_line.nil? converted_line = parse_dotstrings_line(line) strings.merge!(converted_line) unless converted_line.nil? end end end strings end |
#parse_dotstrings_line(line) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/babelish/php2csv.rb', line 22 def parse_dotstrings_line(line) line.strip! if line[0] != ?# && line[0] != ?= m = line.match(/^[\$].*\[[\"\'](.*)[\"\']\]\s*=\s*[\"\'](.*)[\"\'];/) return {m[1] => m[2]} unless m.nil? end end |