Class: Ciphr::Functions::Radix::Radix
Instance Attribute Summary
#invert
Attributes inherited from Function
#args, #options
Class Method Summary
collapse
Instance Method Summary
collapse
invertable?
Methods inherited from Function
inherited, #initialize, invertable?, #prepend, #read
Class Method Details
.aligned ⇒ Object
161
162
163
|
# File 'lib/ciphr/functions/base_radix.rb', line 161
def self.aligned
:right
end
|
.params ⇒ Object
169
170
171
|
# File 'lib/ciphr/functions/base_radix.rb', line 169
def self.params
[:input]
end
|
.variants ⇒ Object
165
166
167
|
# File 'lib/ciphr/functions/base_radix.rb', line 165
def self.variants
(2..36).map{|r| [["r#{r}","rad#{r}","radix#{r}"], {:radix => r}]}
end
|
Instance Method Details
#apply ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/ciphr/functions/base_radix.rb', line 173
def apply
radix = options[:radix]
input = @args[0]
if !invert
num = 0
while chunk = input.read(1)
num = (num << 8) + chunk.bytes.to_a[0]
end
Proc.new do
begin
num && num.to_s(radix)
ensure
num = nil
end
end
else
num = input.read().to_i(radix)
bytes = []
while num > 0
bytes.unshift(num & 0xff)
num = num >> 8
end
Proc.new do
begin
bytes && bytes.pack("c*")
ensure
bytes = nil
end
end
end
end
|