Class: Packr

Inherits:
Object
  • Object
show all
Defined in:
lib/packr.rb,
lib/packr/map.rb,
lib/packr/words.rb,
lib/packr/base62.rb,
lib/packr/parser.rb,
lib/packr/encoder.rb,
lib/packr/minifier.rb,
lib/packr/privates.rb,
lib/packr/shrinker.rb,
lib/packr/constants.rb,
lib/packr/collection.rb,
lib/packr/regexp_group.rb

Defined Under Namespace

Classes: Base62, Collection, Encoder, Map, Minifier, Parser, Privates, RegexpGroup, Shrinker, Words

Constant Summary collapse

VERSION =
'3.1.0'
DATA =
Parser.new.
put("STRING1", IGNORE).
put('STRING2', IGNORE).
put("CONDITIONAL", IGNORE). # conditional comments
put("(OPERATOR)\\s*(REGEXP)", "\\1\\2")
IGNORE =
RegexpGroup::IGNORE
REMOVE =
""
SPACE =
" "

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePackr

Returns a new instance of Packr.



52
53
54
55
56
57
# File 'lib/packr.rb', line 52

def initialize
  @minifier = Minifier.new
  @shrinker = Shrinker.new
  @privates = Privates.new
  @base62   = Base62.new
end

Class Method Details

.encode52(c) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/packr.rb', line 36

def self.encode52(c)
  # Base52 encoding (a-Z)
  encode = lambda do |d|
    (d < 52 ? '' : encode.call((d / 52.0).to_i)) +
        ((d = d % 52) > 25 ? (d + 39).chr : (d + 97).chr)
  end
  encoded = encode.call(c.to_i)
  encoded = encoded[1..-1] + '0' if encoded =~ /^(do|if|in)$/
  encoded
end

.encode62(c) ⇒ Object



31
32
33
34
# File 'lib/packr.rb', line 31

def self.encode62(c)
  (c < 62 ? '' : encode62((c / 62.0).to_i)) +
      ((c = c % 62) > 35 ? (c+29).chr : c.to_s(36))
end

.pack(script, options = {}) ⇒ Object



47
48
49
50
# File 'lib/packr.rb', line 47

def self.pack(script, options = {})
  @packr ||= self.new
  @packr.pack(script, options)
end

Instance Method Details

#pack(script, options = {}) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/packr.rb', line 59

def pack(script, options = {})
  script = @minifier.minify(script)
  script = @shrinker.shrink(script, options[:protect]) if options[:shrink_vars]
  script = @privates.encode(script) if options[:private]
  script = @base62.encode(script) if options[:base62]
  script
end