Форматирование вывода в консоли

Написал простенький скрипт для коммандной строки, который выполняет одну немаловажную для меня задачу - соединяется с сервером статистики моего провайдера, парсит странницу с данными и вытягивает статистику по трафику.

Внешне это выглядит так:

Для красоты и форматирования строк создал следующие методы:

def row(str)
  line = 40
  puts '| '+str+'|'.rjust(line-str.length)
end

def del
  line = 40
  puts '+'+('-'*line)+'+'
end

И они прекрасно работают, пока я использую английский, как видно выше.
Но если строки на русском - все сбивается.

Я пробовал решить проблему следующим путем:

def row(str_ru)
  line = 40
  puts '| '+str+'|'.rjust(line-str_ru.length/2)
end

Т.к. кириллица в 16-битной кодировке, и метод length для кириллической строки возвращает в два раза большее число, чем нужно.

Все бы хорошо, но в строках используются и цифры, и английские буквы, которые, как я понял, в 8-битной кодировке. В итоге все оформление сбивается.

В связи с этим возникли следующие вопросы:

Если аналог метода length для юникода?
Какой аргумент передать методу .rjust, чтобы зафиксировать правую | и чтобы она не съезжала в не зависимости от длины строки идущей спереди?

Заранее благодарен за помощь.

Обсуждение

Re: Форматирование вывода в консоли

А можно посмотреть весь исходник ? :) Мне тоже бы такой не помешал.

cartier watches

ed hardy clothing

est new talent the industry has to offer corum watches by giving the designers a platform to showcase their new creations. Keya features a wide range of home collectibles rolex paintings candles rugs from Turkey burberry watches Syria Egypt corum watches Persia tissot watches Middle East & Africa Internati

jaeger lecoultre watches

ed hardy clothing

Ed Hardy Jeans edhardy women ven further with the American brand bebe which has a couple of variations. Try on the suede-like sheath dress (RM599) or the diagonal beaded-strap dress (RM799). If you’ve got money to splurge tag heuer watches go for Lanvin then longines watches vacheron constantin watches for some French ooh-la-la The T-

rolex watches

ed hardy clothing

panerai watches breitling watches ’s concentrating photovoltaic technology represents a radical departure from “the usual” CPV systems [Full disclosure: I'm the CEO]. Rather than relying on expensive mirrors made of metal or glass hublot watches blancpain watches piaget watches company engineers stretch thin sheets of metal

tag heuer watches

ed hardy clothing

ebel watches panerai watches ed hardy hoodies versace watches calvin klein watch 30-day average daily volume of 3.5 million shares. Look for shares of COH to trade within a new higher trading range with support at $52.96 and move along with its peers in the Textile- Apparel Footwear & Accessories SmarTrend industry. SmarTrend cu

ed hardy t shirts

ed hardy clothing piaget watches rado watch rado watches chopard watches « I think God has blessed our state.One doctor wants Region 8 residents to think more about wearing sensible ed hardy shoes. » Cook’s e-mail came on the heels of a Nov. 11 newsletter from Hardin County party official Peter Morrison of Lumberton longines watch