Class: Code::Object::Base64

Inherits:
Code::Object show all
Defined in:
lib/code/object/base_64.rb

Constant Summary

Constants inherited from Code::Object

NUMBER_CLASSES

Instance Attribute Summary

Attributes included from Concerns::Shared

#methods, #raw

Class Method Summary collapse

Methods inherited from Code::Object

code_new, #code_new, #initialize, maybe, #name, repeat, |

Methods included from Concerns::Shared

#<=>, #==, #as_json, #call, #code_and, #code_as_json, #code_compare, #code_deep_duplicate, #code_different, #code_duplicate, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_falsy?, #code_fetch, code_fetch, code_get, #code_get, #code_greater, #code_greater_or_equal, #code_inclusive_range, #code_inspect, #code_less, #code_less_or_equal, #code_methods, #code_name, #code_nothing?, #code_or, #code_self, #code_set, code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s, #truthy?

Constructor Details

This class inherits a constructor from Code::Object

Class Method Details

.call(**args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/code/object/base_64.rb', line 6

def self.call(**args)
  code_operator = args.fetch(:operator, nil).to_code
  code_arguments = args.fetch(:arguments, []).to_code
  code_value = code_arguments.code_first

  case code_operator.to_s
  when "encode"
    sig(args) { String }
    code_encode(code_value)
  when "decode"
    sig(args) { String }
    code_decode(code_value)
  when "strict_encode"
    sig(args) { String }
    code_strict_encode(code_value)
  when "strict_decode"
    sig(args) { String }
    code_strict_decode(code_value)
  when "urlsafe_encode"
    sig(args) { String }
    code_urlsafe_encode(code_value)
  when "urlsafe_decode"
    sig(args) { String }
    code_urlsafe_decode(code_value)
  else
    super
  end
end

.code_decode(string) ⇒ Object



41
42
43
44
45
# File 'lib/code/object/base_64.rb', line 41

def self.code_decode(string)
  code_string = string.to_code

  String.new(::Base64.decode64(code_string.to_s))
end

.code_encode(string) ⇒ Object



35
36
37
38
39
# File 'lib/code/object/base_64.rb', line 35

def self.code_encode(string)
  code_string = string.to_code

  String.new(::Base64.encode64(code_string.to_s))
end

.code_strict_decode(string) ⇒ Object



53
54
55
56
57
# File 'lib/code/object/base_64.rb', line 53

def self.code_strict_decode(string)
  code_string = string.to_code

  String.new(::Base64.strict_decode64(code_string.to_s))
end

.code_strict_encode(string) ⇒ Object



47
48
49
50
51
# File 'lib/code/object/base_64.rb', line 47

def self.code_strict_encode(string)
  code_string = string.to_code

  String.new(::Base64.strict_encode64(code_string.to_s))
end

.code_urlsafe_decode(string) ⇒ Object



65
66
67
68
69
# File 'lib/code/object/base_64.rb', line 65

def self.code_urlsafe_decode(string)
  code_string = string.to_code

  String.new(::Base64.urlsafe_decode64(code_string.to_s))
end

.code_urlsafe_encode(string) ⇒ Object



59
60
61
62
63
# File 'lib/code/object/base_64.rb', line 59

def self.code_urlsafe_encode(string)
  code_string = string.to_code

  String.new(::Base64.urlsafe_encode64(code_string.to_s))
end