Class: Xmfun::Util::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/xmfun/util/decoder.rb

Class Method Summary collapse

Class Method Details

.decode(input) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/xmfun/util/decoder.rb', line 9

def self.decode(input)
  row, text = strtok(input)

  tmp = text.in_groups(row).transpose.join
  CGI::unescape(tmp).gsub("^", "0")
rescue ArgumentError
  false
end

.strtok(s) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/xmfun/util/decoder.rb', line 18

def self.strtok(s)
  m = /^(\d+)/.match(s)
  raise ArgumentError, "invalid input #{s}" unless m

  [$1.to_i, $'.chars.to_a]
end