Class: MarshalParser::Formatters::Tokens::OneLine

Inherits:
Object
  • Object
show all
Defined in:
lib/marshal-parser/formatters/tokens/one_line.rb

Instance Method Summary collapse

Constructor Details

#initialize(tokens, source_string, hex: nil) ⇒ OneLine

Returns a new instance of OneLine.



7
8
9
10
11
# File 'lib/marshal-parser/formatters/tokens/one_line.rb', line 7

def initialize(tokens, source_string, hex: nil)
  @tokens = tokens
  @source_string = source_string
  @hex = hex
end

Instance Method Details

#stringObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/marshal-parser/formatters/tokens/one_line.rb', line 13

def string
  unless @hex
    @tokens.map do |token|
      string = @source_string[token.index, token.length]
      string =~ /[^[:print:]]/ ? string.dump : string
    end.join(" ")
  else
    @tokens.map do |token|
      string = @source_string[token.index, token.length]
      string = string.bytes.map { |b| "%02X" % b }.join(" ")
    end.join("  ")
  end
end