Class: Lokale::Agent
- Inherits:
-
Object
- Object
- Lokale::Agent
- Defined in:
- lib/lokale.rb
Instance Attribute Summary collapse
-
#lfiles ⇒ Object
readonly
Returns the value of attribute lfiles.
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
-
#proj_path ⇒ Object
readonly
Returns the value of attribute proj_path.
-
#sfiles_proceeded ⇒ Object
readonly
Returns the value of attribute sfiles_proceeded.
Instance Method Summary collapse
- #append_new_macro_calls ⇒ Object
- #copy_base ⇒ Object
- #find_all_localization_calls ⇒ Object
- #get_localization_files ⇒ Object
-
#initialize(proj_path, macros) ⇒ Agent
constructor
A new instance of Agent.
- #proj_files ⇒ Object
Constructor Details
#initialize(proj_path, macros) ⇒ Agent
Returns a new instance of Agent.
140 141 142 143 144 145 146 |
# File 'lib/lokale.rb', line 140 def initialize(proj_path, macros) @proj_path = proj_path @macros = macros get_localization_files find_all_localization_calls end |
Instance Attribute Details
#lfiles ⇒ Object (readonly)
Returns the value of attribute lfiles.
138 139 140 |
# File 'lib/lokale.rb', line 138 def lfiles @lfiles end |
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
138 139 140 |
# File 'lib/lokale.rb', line 138 def macros @macros end |
#proj_path ⇒ Object (readonly)
Returns the value of attribute proj_path.
138 139 140 |
# File 'lib/lokale.rb', line 138 def proj_path @proj_path end |
#sfiles_proceeded ⇒ Object (readonly)
Returns the value of attribute sfiles_proceeded.
138 139 140 |
# File 'lib/lokale.rb', line 138 def sfiles_proceeded @sfiles_proceeded end |
Instance Method Details
#append_new_macro_calls ⇒ Object
185 186 187 |
# File 'lib/lokale.rb', line 185 def append_new_macro_calls end |
#copy_base ⇒ Object
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/lokale.rb', line 174 def copy_base en_files = @lfiles.group_by { |f| f.lang }["en"].select { |f| f.strings_file? } base_files = @lfiles.group_by { |f| f.lang }["Base"].select { |f| f.strings_file? } en_files.each do |en| base = base_files.select { |f| f.full_name == en.full_name }.sample next if base.nil? IO.copy_stream(en.path, base.path) end end |
#find_all_localization_calls ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/lokale.rb', line 161 def find_all_localization_calls @macros.each { |m| m.clear_calls } @sfiles_proceeded = 0 proj_files do |file| next unless file.source_file? file_content = File.read(file) @macros.each { |macro| macro.read_from file_content } @sfiles_proceeded += 1 end end |
#get_localization_files ⇒ Object
156 157 158 159 |
# File 'lib/lokale.rb', line 156 def get_localization_files return @lfiles unless @lfiles.nil? @lfiles = proj_files.map { |file| LFile.try_to_read(file) }.compact end |
#proj_files ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/lokale.rb', line 148 def proj_files if block_given? Dir.glob("#{@proj_path}/**/**") { |f| yield f } else Dir.glob("#{@proj_path}/**/**") end end |