Module: Integer::Base
- Defined in:
- lib/integer/base.rb,
lib/integer/base/version.rb,
lib/integer/base/refinementable.rb,
lib/integer/base/singleton_class.rb
Defined Under Namespace
Modules: IntegerPrepender, StringPrepender
Classes: InvalidCharacterError
Constant Summary
collapse
- SPECIAL_CHAR_PATTERN =
/[\x00-\x20\-\+]/
- STANDARD_CHARS =
Hash.new{|*|raise KeyError}.tap {|standards|
1.upto 10 do |n|
standards[n] = (:'0'..((n - 1).to_s.to_sym)).to_a.freeze
end
alphabets = (:A..:Z).to_a
11.upto 36 do |n|
standards[n] = [
*standards[10], *alphabets.slice(0, n - 10)
].freeze
end
standards[:BINARY] = standards[2]
}.freeze
- VERSION =
'0.1.0'.freeze
Class Method Summary
collapse
Class Method Details
.integer_for_string(str, positional_chars) ⇒ Integer
Also known as:
parse
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/integer/base/singleton_class.rb', line 10
def integer_for_string(str, positional_chars)
str = str.to_str.downcase
sign = parse_sign! str
abs = (
case positional_chars.length
when 1
parse_unary_abs str, positional_chars.first
else
parse_positional_abs str, positional_chars
end
)
(sign == :-) ? -abs : abs
end
|
.string_for_integer(num, positional_chars) ⇒ String
Also known as:
string_for
31
32
33
34
35
36
37
38
|
# File 'lib/integer/base/singleton_class.rb', line 31
def string_for_integer(num, positional_chars)
case positional_chars.length
when 1
string_unary_for num, positional_chars.first
else
string_positional_for num, positional_chars
end
end
|