extraction_token_util 0.0.2 → 0.0.3a11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/extraction_token_util.rb +52 -31
  3. metadata +33 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77df6f96a575e9474c235cfd5896debda89c3e9a482ee8777e1a1132d6cf5f33
4
- data.tar.gz: 66af9ab43913879d49019e9cb3b6a83ed40985e13d71fdd1f594d42003045d75
3
+ metadata.gz: 807964dad3726d71b70ad733c4d1d2362ad0d7ece464e277d5c86868d616db12
4
+ data.tar.gz: 947c1a665fdf8e23bf01789b17ce487aa8e62d8f6bbbc3214e7728c4531e06a4
5
5
  SHA512:
6
- metadata.gz: c67131dd5fd0fb4ad3144eb5219669c22d869f8e1efff33a1282ded41fc43a4cf5e5f068b4b53ca122195af922500481a56b08bd15f7581ad625fc6db44eb39d
7
- data.tar.gz: 196c12621df992657b964c287b8b32009283cc40e36482fa9bd42076d8f881936746d4c27a056131daa64a0f4038ef5729e1f523b0bc8e33ce1eb801c5dd59b2
6
+ metadata.gz: aa5a205ebdf99bd9b2b314fe02a9e58f8303955a075b1a79ca105c3cb678cc90af08eb1eeeea938938fc8af4b14a97e9176dc268a68ced77cec5eb3eb8205422
7
+ data.tar.gz: 77973aab9f3e5bc6256a5d2f746df0889dfda93ff162aa2ddc24034d9869634ac3dcb1e2798612a6fedaf9fc6bbf0520d75599a31645b8da03b7838c780195c9
@@ -1,85 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # This Gem provides support for common string operations with tokens in
5
+ # Extraction lims like:
6
+ # - quoting / unquoting strings
7
+ # - padding / unpadding a string of digits until reaching a fixed size by
8
+ # using zeroes support to perform recognizion of the following tokens:
9
+ # - generate the address positions of the wells of a rack (A01, B01... F12)
10
+ #
11
+ # Also provides pattern recognision for UUID, Wildcard variables (Eg: ?a,
12
+ # ?rack, etc.), Fluidx barcodes: (Eg: FR1234678), Well Location: (Eg: A02, F11)
13
+ #
1
14
  module ExtractionTokenUtil
2
- def self.UUID_REGEXP
3
- /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
4
- end
15
+ UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.freeze
16
+ WILDCARD = /\?\w*/.freeze
17
+ LOCATION = /^([A-H])(\d{1,2})$/.freeze
5
18
 
6
19
  def self.fluidx_barcode_prefix
7
20
  'F'
8
21
  end
9
22
 
10
- def self.WILDCARD_REGEXP
11
- /\?\w*/
12
- end
13
-
14
- def self.LOCATION_REGEXP
15
- /^([A-H])(\d{1,2})$/
16
- end
17
-
18
- def self.is_uuid?(str)
19
- str.kind_of?(String) && !str.match(ExtractionTokenUtil.UUID_REGEXP).nil?
23
+ def self.uuid?(str)
24
+ str.is_a?(String) && !str.match(ExtractionTokenUtil::UUID).nil?
20
25
  end
21
26
 
22
27
  def self.quote_if_uuid(str)
23
- return quote(str) if is_uuid?(str)
24
- return str
28
+ return quote(str) if uuid?(str)
29
+
30
+ str
25
31
  end
26
32
 
27
- def self.is_valid_fluidx_barcode?(barcode)
33
+ def self.valid_fluidx_barcode?(barcode)
28
34
  barcode.to_s.start_with?(fluidx_barcode_prefix)
29
35
  end
30
36
 
31
37
  def self.uuid(str)
32
- str.match(ExtractionTokenUtil.UUID_REGEXP)[0]
38
+ str.match(ExtractionTokenUtil::UUID)[0]
33
39
  end
34
40
 
35
- def self.is_wildcard?(str)
36
- str.kind_of?(String) && !str.match(ExtractionTokenUtil.WILDCARD_REGEXP).nil?
41
+ def self.wildcard?(str)
42
+ str.is_a?(String) && !str.match(ExtractionTokenUtil::WILDCARD).nil?
37
43
  end
38
44
 
39
45
  def self.kind_of_asset_id?(str)
40
- !!(str.kind_of?(String) && (is_wildcard?(str) || is_uuid?(str)))
46
+ (str.is_a?(String) && (wildcard?(str) || uuid?(str)))
41
47
  end
42
48
 
43
49
  def self.to_asset_group_name(wildcard)
44
50
  return wildcard if wildcard.nil?
51
+
45
52
  wildcard.gsub('?', '')
46
53
  end
47
54
 
48
55
  def self.generate_positions(letters, columns)
49
- size=letters.size * columns.size
50
- location_for_position = size.times.map do |i|
51
- "#{letters[(i%letters.length).floor]}#{pad((columns[(i/letters.length).floor]).to_s,'0',2)}"
56
+ size = letters.size * columns.size
57
+ size.times.map do |idx|
58
+ letter = position_letter_for_index(idx, letters)
59
+ number = position_number_for_index(idx, letters, columns)
60
+ "#{letter}#{number}"
52
61
  end
53
62
  end
54
63
 
55
- def self.pad(str,chr,size)
56
- "#{(size-str.size).times.map{chr}.join('')}#{str}"
64
+ def self.position_letter_for_index(idx, letters)
65
+ letters[(idx % letters.length).floor]
66
+ end
67
+
68
+ def self.position_number_for_index(idx, letters, columns)
69
+ pad((columns[(idx / letters.length).floor]).to_s, '0', 2)
70
+ end
71
+
72
+ def self.pad(str, chr, size)
73
+ "#{(size - str.size).times.map { chr }.join('')}#{str}"
57
74
  end
58
75
 
59
76
  def self.unpad_location(location)
60
77
  return location unless location
78
+
61
79
  loc = location.match(/(\w)(0*)(\d*)/)
62
- loc[1]+loc[3]
80
+ loc[1] + loc[3]
63
81
  end
64
82
 
65
83
  def self.pad_location(location)
66
84
  return location unless location
67
- parts = location.match(ExtractionTokenUtil.LOCATION_REGEXP)
68
- return nil if parts.length == 0
85
+
86
+ parts = location.match(ExtractionTokenUtil::LOCATION)
87
+ return nil if parts.to_a.empty?
88
+
69
89
  letter = parts[1]
70
90
  number = parts[2]
71
- number = ExtractionTokenUtil.pad(number,"0",2) unless number.length == 2
91
+ number = ExtractionTokenUtil.pad(number, '0', 2) unless number.length == 2
72
92
  "#{letter}#{number}"
73
93
  end
74
94
 
75
95
  def self.quote(str)
76
96
  return str unless str
97
+
77
98
  "\"#{str}\""
78
99
  end
79
100
 
80
101
  def self.unquote(str)
81
102
  return str unless str
82
- str.gsub(/\"/,"")
83
- end
84
103
 
104
+ str.gsub(/\"/, '')
105
+ end
85
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extraction_token_util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3a11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Martin Rojo
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.80'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.80'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  description:
28
56
  email:
29
57
  executables: []
@@ -48,11 +76,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
76
  version: '0'
49
77
  required_rubygems_version: !ruby/object:Gem::Requirement
50
78
  requirements:
51
- - - ">="
79
+ - - ">"
52
80
  - !ruby/object:Gem::Version
53
- version: '0'
81
+ version: 1.3.1
54
82
  requirements: []
55
- rubygems_version: 3.0.3
83
+ rubyforge_project:
84
+ rubygems_version: 2.7.7
56
85
  signing_key:
57
86
  specification_version: 4
58
87
  summary: Set of Ruby methods to provide lexical support to common formats in use in