Module: EnvCompat
- Defined in:
- lib/env_compat.rb,
lib/env_compat/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
Class Method Details
.auto(tag, str) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/env_compat.rb', line 5 def auto tag, str if str[/#{tag}_/i] decode str[tag.length.+(1)..-1] else "#{tag.upcase}_#{encode str}" end end |
.decode(str) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/env_compat.rb', line 29 def decode str builder = '' _ = CodeBlock.new str.chars.each do |chr| next _.cycle if chr == '_' if _.in_block? case chr when *mapping.keys builder << mapping[chr] else raise "Invalid input!" end else builder << chr end end builder.upcase end |
.encode(str) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/env_compat.rb', line 13 def encode str builder = '' _ = CodeBlock.new str.chars.each do |chr| case chr when *mapping.values builder = _.toggle(builder) unless _.in_block? builder << mapping.invert[chr] else builder = _.toggle(builder) if _.in_block? builder << chr end end builder.upcase end |