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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e34e411f940ad6241d49bd8a42871699eddb62895eb2c6d9ecaf4029fca646c
4
- data.tar.gz: 888953fea926bdbcb9e4a2ec1cbeb954e11640639f8bfb417d777b859301ac17
3
+ metadata.gz: 37a226b502b620d330ae1e8756fb46338257505fe043bf593f6341ad39fbf61f
4
+ data.tar.gz: 3de0c722430b186a25a0589ed1540dfc0379113e0237658a6d3098669e798d1a
5
5
  SHA512:
6
- metadata.gz: 7d6119e25ae6c66830f6240ce746e585d37cba26f6f1516cf0c7eb88fc97d303ac639a40b78cb9c5141adaf3b8f13a4da4c8fba7345af38e65d8576b82888e29
7
- data.tar.gz: 991d0d160cfa89d2724b2dd643fde9881812a5a8bc953dbabf1949665064fa58d850b7771e989edf035fdea7229c0c5bc902d77928f2a15549d10a542773e9e2
6
+ metadata.gz: 7314ec506c69d3731552647610df12911063c0c689cec2f4380b781556c3d769ac77defcb7627f180da891fb7e1e0a1af90833568991a84b4f4baef2500fff07
7
+ data.tar.gz: ca66931fcd2e919dfd02f0f63db2ed5aab14b4cb911bd285db487d7c004ac3b5783f47612445d16a8f0b2d8087601940c9dcc8325d57be5161598d6171474a5e
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module CharacterEnumerator
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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.0.0
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: 2019-10-12 00:00:00.000000000 Z
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.0.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