Sha256: 250b8945b0e9e8ba7c2a00dc720dc4fb95b76cbbdcc87111bc623ca31afe0a1c

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

# coding: utf-8

module ThinReports
  module Core::Shape::TextBlock
    
    # @private
    class Formatter::Padding < Formatter::Basic
      
    private
    
    ruby_18 do
      def apply_format_to(value)
        value = value.to_s
        
        char_length = value.unpack('U*').length
        pad_length  = format.format_padding_length
        
        if pad_length > char_length
          pad_strs = format.format_padding_char * (pad_length - char_length)
          if format.format_padding_rdir?
            value + pad_strs
          else
            pad_strs + value
          end
        else
          value
        end
      end
    end
    
    ruby_19 do
      def apply_format_to(value)
        value.to_s.send(format.format_padding_rdir? ? :ljust : :rjust,
                        format.format_padding_length,
                        format.format_padding_char)
      end
    end
    
      def applicable?(value)
        !format.format_padding_char.blank? && format.format_padding_length > 0
      end
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinreports-0.7.7 lib/thinreports/core/shape/text_block/formatter/padding.rb
thinreports-0.7.6 lib/thinreports/core/shape/text_block/formatter/padding.rb
thinreports-0.7.5 lib/thinreports/core/shape/text_block/formatter/padding.rb
thinreports-0.7.0 lib/thinreports/core/shape/text_block/formatter/padding.rb