class Pppt::Helpers
Public Class Methods
format_page_number(page)
click to toggle source
# File lib/pppt/helpers.rb, line 31 def self.format_page_number(page) index = page['page'] || '-' title = page['action'] || (page['title'] && " - #{page['title']}") || page['h1'] || page['h2'] || page['h3'] || (page['body'] && " #{Helpers.truncate_screen_width(page['body'].join(''), 15)}") format('%02s %s', index, title) end
screen_width(str)
click to toggle source
# File lib/pppt/helpers.rb, line 26 def self.screen_width(str) hankaku_len = str.each_char.count(&:ascii_only?) hankaku_len + (str.size - hankaku_len) * 2 end
split_screen_width(str, width = 40)
click to toggle source
# File lib/pppt/helpers.rb, line 13 def self.split_screen_width(str, width = 40) s = i = r = 0 str.each_char.each_with_object([]) do |c, res| i += c.ascii_only? ? 1 : 2 r += 1 next res if i < width res << str[s, r] s += r i = r = 0 res end << str[s, r] end
truncate_screen_width(str, width, suffix = '...')
click to toggle source
# File lib/pppt/helpers.rb, line 2 def self.truncate_screen_width(str, width, suffix = '...') i = 0 str.each_char.inject(0) do |c, x| c += x.ascii_only? ? 1 : 2 i += 1 next c if c < width return str[0, i] + suffix end str end