Sha256: 5f31dab7b0514143067dbb2f0bc65008acb1f6effa1fc457e74861c14311a354

Contents?: true

Size: 796 Bytes

Versions: 2

Compression:

Stored size: 796 Bytes

Contents

module LanguageCards
  module Helpers
    module ViewHelper
      def divider
        '~' * SUBMENUWIDTH
      end

      def t str
        I18n.t str
      end

      def draw left=nil, center=nil, right=nil
        width = SUBMENUWIDTH
        str = left.to_s
        str = str + center.to_s.rjust(width/2 - str.length + center.to_s.length/2)
        str + right.to_s.rjust(width - str.length)
      end

      def clear
        printf ::LanguageCards::ESC::CLEAR
      end

      def humanize string
        "#{string}".split('_').map(&:capitalize).join(' ')
      end

      def snake string
        "#{string}".gsub(/(.)([A-Z])/, '\1_\2').downcase
      end

      def wordwrap words
        "#{words}".gsub(/(.{1,#{SUBMENUWIDTH - 7}})(\s+|\Z)/, "\\1\n\t").strip
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
language_cards-0.3.2 lib/language_cards/helpers/view_helper.rb
language_cards-0.3.1 lib/language_cards/helpers/view_helper.rb