character_enumerator 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/character_enumerator.rb +21 -0
- data/lib/character_enumerator/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37a226b502b620d330ae1e8756fb46338257505fe043bf593f6341ad39fbf61f
|
4
|
+
data.tar.gz: 3de0c722430b186a25a0589ed1540dfc0379113e0237658a6d3098669e798d1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7314ec506c69d3731552647610df12911063c0c689cec2f4380b781556c3d769ac77defcb7627f180da891fb7e1e0a1af90833568991a84b4f4baef2500fff07
|
7
|
+
data.tar.gz: ca66931fcd2e919dfd02f0f63db2ed5aab14b4cb911bd285db487d7c004ac3b5783f47612445d16a8f0b2d8087601940c9dcc8325d57be5161598d6171474a5e
|
data/lib/character_enumerator.rb
CHANGED
@@ -2,6 +2,9 @@ require "character_enumerator/version"
|
|
2
2
|
|
3
3
|
module CharacterEnumerator
|
4
4
|
module Implementation
|
5
|
+
VALID_CHARACTERS_REGEXP = /\A[A-Z]+\z/
|
6
|
+
BLANK_STRING_REGEXP = /\A[[:space:]]*\z/
|
7
|
+
|
5
8
|
def generate(size)
|
6
9
|
Enumerator.new(size) do |y|
|
7
10
|
size.times do |index|
|
@@ -16,6 +19,24 @@ module CharacterEnumerator
|
|
16
19
|
internal_integer_to_characters(value)
|
17
20
|
end
|
18
21
|
|
22
|
+
def characters_to_integer(characters)
|
23
|
+
raise ArgumentError, "argument must be string" unless characters.is_a?(String)
|
24
|
+
is_blank =\
|
25
|
+
if characters.respond_to?(:blank?)
|
26
|
+
characters.blank?
|
27
|
+
else
|
28
|
+
characters.match?(BLANK_STRING_REGEXP)
|
29
|
+
end
|
30
|
+
return nil if is_blank
|
31
|
+
raise ArgumentError, "argument must be string matching regexp: #{VALID_CHARACTERS_REGEXP.inspect}" unless characters.match?(VALID_CHARACTERS_REGEXP)
|
32
|
+
result = 0
|
33
|
+
characters.unpack("C*") do |number|
|
34
|
+
result *= 26
|
35
|
+
result += number - 64
|
36
|
+
end
|
37
|
+
result - 1
|
38
|
+
end
|
39
|
+
|
19
40
|
private
|
20
41
|
|
21
42
|
def internal_integer_to_characters(value)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: character_enumerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krists Ozols
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.1.4
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Ruby enumerator that converts integers to character representation(Like in
|