Class: Locraft::Localization

Inherits:
Object
  • Object
show all
Defined in:
lib/locraft/localization.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



4
5
6
# File 'lib/locraft/localization.rb', line 4

def comment
  @comment
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/locraft/localization.rb', line 5

def key
  @key
end

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/locraft/localization.rb', line 3

def language
  @language
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/locraft/localization.rb', line 6

def value
  @value
end

Class Method Details

.load_with_csv_row(row, config, lang) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/locraft/localization.rb', line 8

def self.load_with_csv_row(row, config, lang)
  localization = Localization.new
  localization.language = lang
  localization.comment = row[config.gdoc_comments_column]&.strip
  localization.key = (row[config.gdoc_keys_column] || row[config.default_lang])&.strip
  localization.value = (row[lang] || row[config.default_lang])&.strip
  localization
end

Instance Method Details

#to_lineObject



21
22
23
24
25
26
27
28
# File 'lib/locraft/localization.rb', line 21

def to_line
  content = ''
  if valid?
    content += "/* #{comment} */" unless comment.nil?
    content += %(\n"#{key}" = "#{value}";\n)
  end
  content
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/locraft/localization.rb', line 17

def valid?
  !(key.nil? or value.nil?)
end