Class: AdLocalize::CsvParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ad_localize/csv_parser.rb

Constant Summary collapse

CSV_WORDING_KEYS_COLUMN =
"key"
PLURAL_KEY_REGEXP =
/\#\#\{(\w+)\}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCsvParser

Returns a new instance of CsvParser.



8
9
10
# File 'lib/ad_localize/csv_parser.rb', line 8

def initialize
  @locales = []
end

Instance Attribute Details

#localesObject

Returns the value of attribute locales.



6
7
8
# File 'lib/ad_localize/csv_parser.rb', line 6

def locales
  @locales
end

Instance Method Details

#extract_data(file_name) ⇒ Object

Raise a StandardError if no locale is detected in the csv



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ad_localize/csv_parser.rb', line 13

def extract_data(file_name)
  data = {}
  CSV.foreach(file_name, headers: true, skip_blanks: true) do |row|
    validity_status = check_row(row)
    if validity_status.zero?
      next
    elsif validity_status == -1
      exit
    else
      find_locales(row) if locales.empty?
      row_data = parse_row(row)
      data.deep_merge!(row_data) unless row_data.nil?
    end
  end
  data
end