Class: Babelish::XcodeMacros
- Inherits:
-
Object
- Object
- Babelish::XcodeMacros
- Defined in:
- lib/babelish/xcode_macros.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#table ⇒ Object
Returns the value of attribute table.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(table = "Localizable", keys = {}) ⇒ XcodeMacros
constructor
A new instance of XcodeMacros.
- #process(table, keys, comments = {}) ⇒ Object
- #write_content(file_path) ⇒ Object
Constructor Details
#initialize(table = "Localizable", keys = {}) ⇒ XcodeMacros
Returns a new instance of XcodeMacros.
4 5 6 7 8 |
# File 'lib/babelish/xcode_macros.rb', line 4 def initialize(table = "Localizable", keys = {}) @content = "" @table = table @keys = keys end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/babelish/xcode_macros.rb', line 3 def content @content end |
#keys ⇒ Object
Returns the value of attribute keys.
3 4 5 |
# File 'lib/babelish/xcode_macros.rb', line 3 def keys @keys end |
#table ⇒ Object
Returns the value of attribute table.
3 4 5 |
# File 'lib/babelish/xcode_macros.rb', line 3 def table @table end |
Class Method Details
.write_macros(file_path, table, keys, comments = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/babelish/xcode_macros.rb', line 10 def self.write_macros(file_path, table, keys, comments = {}) instance = XcodeMacros.new instance.process(table, keys, comments) instance.write_content(file_path) end |
Instance Method Details
#process(table, keys, comments = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/babelish/xcode_macros.rb', line 16 def process(table, keys, comments = {}) keys.each do |key| clean_key = key.gsub(' ', '') clean_key.gsub!(/[[:punct:]]/, '_') clean_key.gsub!('__', '_') clean_key = clean_key[1..clean_key.size-1] if clean_key[0] == '_' clean_key = clean_key[0..clean_key.size-2] if clean_key.size > 1 and clean_key[clean_key.size-1] == '_' macro_name = "LS_#{clean_key.upcase}" macro_name += "_#{table.upcase}" if table != "Localizable" comment = comments[key] @content << String.new(<<-EOS) #define #{macro_name} NSLocalizedStringFromTable(@"#{key}",@"#{table}",@"#{comment.to_s}") EOS end @content end |
#write_content(file_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/babelish/xcode_macros.rb', line 33 def write_content(file_path) header = String.new(<<-EOS) // // file_path // // This file was generated by Babelish // // https://github.com/netbe/babelish // EOS header.gsub! "file_path", File.basename(file_path) file = File.new(file_path, "w") file.write header + @content file.close end |