Class: ZSteg::Result::Text

Inherits:
Struct
  • Object
show all
Defined in:
lib/zsteg/result.rb

Direct Known Subclasses

PartialText, UnicodeText, WholeText

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#offsetObject

Returns the value of attribute offset

Returns:

  • (Object)

    the current value of offset



25
26
27
# File 'lib/zsteg/result.rb', line 25

def offset
  @offset
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



25
26
27
# File 'lib/zsteg/result.rb', line 25

def text
  @text
end

Class Method Details

.from_matchdata(m) ⇒ Object



47
48
49
# File 'lib/zsteg/result.rb', line 47

def self.from_matchdata m
  self.new m[0], m.begin(0)
end

Instance Method Details

#one_char?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# 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_sObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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