Class: Ciphr::Functions::URL::UrlEncoding

Inherits:
InvertibleFunction show all
Defined in:
lib/ciphr/functions/url.rb

Overview

TODO: differentiate between URL and CGI encoding (with ‘+’ char)

Instance Attribute Summary

Attributes inherited from InvertibleFunction

#invert

Attributes inherited from Function

#args, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InvertibleFunction

invertable?

Methods inherited from Function

aligned, inherited, #initialize, invertable?, #prepend, #read

Constructor Details

This class inherits a constructor from Ciphr::Functions::Function

Class Method Details

.paramsObject



34
35
36
# File 'lib/ciphr/functions/url.rb', line 34

def self.params 
  [:input]
end

.variantsObject



28
29
30
31
32
# File 'lib/ciphr/functions/url.rb', line 28

def self.variants
  [
    [['url','uri','cgi'],{}]
  ]
end

Instance Method Details

#applyObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ciphr/functions/url.rb', line 6

def apply
  input = @args[0]
  if !invert
    Proc.new do
      chunk = input.read(1)
      chunk && CGI.escape(chunk)
    end
  else
    Proc.new do
      chunk = input.read(1)
      if (chunk == "%")
        chunk += input.read(2)
        chunk && CGI.unescape(chunk)
      elsif chunk == '+'
        ' '
      else
        chunk
      end
    end
  end
end