class ZSteg::Result::Text

Public Class Methods

from_matchdata(m) click to toggle source
# File lib/zsteg/result.rb, line 47
def self.from_matchdata m
  self.new m[0], m.begin(0)
end

Public Instance Methods

one_char?() click to toggle source
# File lib/zsteg/result.rb, line 26
def one_char?
  (text =~ /\A(.)\1+\Z/m) == 0
rescue # invalid byte sequence in UTF-8
  text.chars.to_a.uniq.size == 1 # ~10x slower than regexp
end
to_s() click to toggle source
# File lib/zsteg/result.rb, line 32
def to_s
  "text: ".gray +
    if one_char?
      "[#{text[0].inspect} repeated #{text.size} times]".gray
    elsif offset == 0
      # first byte of data is also first char of text
      text.inspect.bright_red
    elsif text.size > 10 && text[' '] && text =~ /\A[a-z0-9 .,:!_-]+\Z/i
      # text is ASCII with spaces
      text.inspect.bright_red
    else
      text.inspect
    end
end