Module: I18nFlow::Util
Instance Method Summary collapse
- #extract_args(text) ⇒ Object
- #filepath_to_scope(filepath) ⇒ Object
- #find_file_upward(*file_names) ⇒ Object
- #parse_options(args) ⇒ Object
- #scope_to_filepath(scopes) ⇒ Object
Instance Method Details
#extract_args(text) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/i18n_flow/util.rb', line 4 def extract_args(text) text.to_s .gsub(/%%/, '') .scan(/%\{([^\}]+)\}/) .flatten .sort end |
#filepath_to_scope(filepath) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/i18n_flow/util.rb', line 12 def filepath_to_scope(filepath) *scopes, filename = filepath.split('/') *basename, locale, _ = filename.split('.') ([locale] + scopes + basename).compact.reject(&:empty?) end |
#find_file_upward(*file_names) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/i18n_flow/util.rb', line 24 def find_file_upward(*file_names) pwd = Dir.pwd base = Hash.new { |h, k| h[k] = pwd } file = {} while base.values.all? { |b| '.' != b && '/' != b } file_names.each do |name| file[name] = File.join(base[name], name) base[name] = File.dirname(base[name]) return file[name] if File.exists?(file[name]) end end nil end |
#parse_options(args) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/i18n_flow/util.rb', line 41 def (args) = {} args.reject! do |arg| case arg when /^-([a-z0-9])$/i, /^--([a-z0-9][a-z0-9-]*)$/i [$1] = true when /^--([a-z0-9][a-z0-9-]*)=(.+)$/i [$1] = $2 else break end end end |
#scope_to_filepath(scopes) ⇒ Object
19 20 21 22 |
# File 'lib/i18n_flow/util.rb', line 19 def scope_to_filepath(scopes) locale, *components = scopes [components.join('/'), locale, 'yml'].compact.reject(&:empty?).join('.') end |