class ExtractCatalog

Public Instance Methods

main() click to toggle source
# File vendor/qwik/lib/qwik/dev-extract-catalog.rb, line 31
def main
  mypath = Pathname.new(__FILE__)

  catalog_ja = mypath.parent + 'catalog-ja.rb'
  ar = parse(catalog_ja)
  outpath = Pathname.new '../../interfaces-web.txt'
  output(outpath, ar)

  catalog_ml_ja = mypath.parent + 'catalog-ml-ja.rb'
  ar = parse(catalog_ml_ja)
  outpath = Pathname.new '../../interfaces-ml.txt'
  output(outpath, ar)
end
output(outpath, ar) click to toggle source
# File vendor/qwik/lib/qwik/dev-extract-catalog.rb, line 73
def output(outpath, ar)
  outpath.open('w') {|out|
    ar.each {|e, j|
      next if e.nil?
      next if j.nil?

      e.del!(/\A'/)
      j.del!(/['"],\z/)
      e.del!(/\\n/)
      j.del!(/\\n/)

      e.gsub!(/\\\"/) { '"' }

      next if e.empty?
      next if j.empty?

      next if e == '->'
      next if e == '<-'
      next if j == '→'
      next if j == '←'

      out.puts j
      out.puts e
      out.puts
    }
  }
end
parse(path) click to toggle source
# File vendor/qwik/lib/qwik/dev-extract-catalog.rb, line 45
def parse(path)
  str = path.read

  str2 = ''
  str.each_line {|line|
    line.trim_line!

    next if line.empty?

    case line
    when /^#/, /^module /, /^class /, /^def /, /^\{/, /^\}/, /^end$/,
        /^:charset/, /^:codeconv/
      next
    end

    str2 << line
  }

  ar = []
  lines = str2.split(/['"],['"]/)
  lines.each {|line|
    e, j = line.split(/['"]\s*=>\s*['"]/)
    ar << [e, j]
  }

  return ar
end