Module: Fewer::Serializer

Defined in:
lib/fewer/serializer.rb

Class Method Summary collapse

Class Method Details

.decode(root, encoded) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/fewer/serializer.rb', line 4

def decode(root, encoded)
  files = ls(root)
  delimeter = files.length > 36 ? ',' : ''

  encoded.split(delimeter).map { |char|
    files[char.to_i(36)]
  }.compact
end

.encode(root, paths) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/fewer/serializer.rb', line 13

def encode(root, paths)
  files = ls(root)
  delimeter = files.length > 36 ? ',' : ''

  paths.map { |path|
    index = files.index(path)
    index ? index.to_s(36) : nil
  }.compact.join(delimeter)
end