Class: FdupesParser::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/fdupes_parser/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(s_entry) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fdupes_parser/entry.rb', line 5

def parse(s_entry)
  bytes_each_line, *paths = *s_entry.each_line(chomp: true)
  md = /\A(?<size>\d+) bytes each:\z/.match(bytes_each_line)
  if !md
    raise FdupesParser::Error.new("Malformed line is detected: line=#{bytes_each_line.inspect}")
  end

  size = md[:size].to_i
  new(size:, paths:)
end

Instance Method Details

#to_sObject



17
18
19
20
21
22
23
24
# File 'lib/fdupes_parser/entry.rb', line 17

def to_s
  s = +"#{size} bytes each:\n"
  paths.each do |path|
    s << path << "\n"
  end
  s << "\n"
  return s
end