setfu 1.0.1 → 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
  SHA1:
3
- metadata.gz: 430de38e589c6c82726b4b883d3e129c44b3c5cd
4
- data.tar.gz: 0eb92d115917ae3e7cc2d90489c4493a9fe92958
3
+ metadata.gz: 98a90b0258e875fad04750814d8324d7a6a01d09
4
+ data.tar.gz: 871a1632723b4d212128bc1cba8e08c455ea464c
5
5
  SHA512:
6
- metadata.gz: e4fda85793d67822adaeb129719dc9963af2ec0e40f7c7f53b9ef332b456c3701cb75ae75890e0f17f078c74d7ef8f3dfe0dfbb1c36ba4d60d1aa5ea0523172e
7
- data.tar.gz: 3d78df242c0843813d8cf7a42f26c211445fba331c1b9d4aa6067e14df64c4544fd1056f2de0b277850b786758b451f105f08368bf99c8c54b8c5d1be0406516
6
+ metadata.gz: b0ce98d4fdbfd73362b9a5d0b76b6fd5eecf623d47a9afd9e61e58ec81190c020210b21dc3547bb7c272f1295264b9c62c15af32d4a84a2e030a340da5822c4f
7
+ data.tar.gz: bab004705084529b0391eb2354c94077b0a73b36d630e1500062361a67244fa8f1cda39a3a09e8b9ec3794ad55b519a70ac031fcdc151cc5ef1f4ac956c760b7
data/README.md CHANGED
@@ -70,6 +70,12 @@ Methods:
70
70
  :mode_proper case(s) -> when a ... validates on a < s
71
71
  :mode_super case(s) -> when a ... validates on s <= a
72
72
  :mode_superproper case(s) -> when a ... validates on s < a
73
+ .add_opposing_case! >> for every letter character in set, the inverse case of that character is added to the set.
74
+ ex: y = "aBc".to_set.add_opposing_case! ... y == "abcABC"
75
+ .add_lowercase_chars! >> same as .add!('a'..'z')
76
+ .add_uppercase_chars! >> same as .add!('A'..'Z')
77
+ .add_digit_chars! >> same as .add!('0'..'9')
78
+ .add_parse_chars! >> adds white space and typical non-alphanumeric chars found on typical keyboard
73
79
 
74
80
  Properties:
75
81
  .entropy >> Total number of possible states. Like the universe, can only get bigger.
data/lib/setfu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Setfu
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/setfu.rb CHANGED
@@ -7,6 +7,10 @@ class Set
7
7
  @entropy = ent unless @entropy > ent
8
8
  end
9
9
 
10
+ def to_set
11
+ return self
12
+ end
13
+
10
14
  def mode
11
15
  return @mode
12
16
  end
@@ -54,6 +58,52 @@ class Set
54
58
  add! [0..47, 58..64, 91..96, 123..126]
55
59
  self
56
60
  end
61
+
62
+ def add_parse_chars
63
+ dup.add_parse_chars!
64
+ end
65
+
66
+ def add_digit_chars!
67
+ add! [48..57]
68
+ self
69
+ end
70
+
71
+ def add_digit_chars
72
+ dup.add_digit_chars!
73
+ end
74
+
75
+ def add_uppercase_chars!
76
+ add! [65..90]
77
+ self
78
+ end
79
+
80
+ def add_uppercase_chars
81
+ dup.add_uppercase_chars!
82
+ end
83
+
84
+ def add_lowercase_chars!
85
+ add! [97..122]
86
+ self
87
+ end
88
+
89
+ def add_lowercase_chars
90
+ dup.add_lowercase_chars!
91
+ end
92
+
93
+ def add_opposing_case!
94
+ aa = Set.new.add_lowercase_chars!
95
+ bb = Set.new.add_uppercase_chars!
96
+ ka = aa & self # subset lower case
97
+ kb = bb & self # subset upper case
98
+ @bits |= ka.to_i >> 32
99
+ @bits |= kb.to_i << 32
100
+ self.entropy = 32 + kb.recalculate_entropy! if self.entropy <= 123
101
+ self
102
+ end
103
+
104
+ def add_opposing_case
105
+ dup.add_opposing_case!
106
+ end
57
107
 
58
108
  # this only works on integer ... String, Array, Range does not implement: &, |, ^
59
109
  def coerce(other)
@@ -64,6 +114,7 @@ class Set
64
114
  def dup
65
115
  rtn = Set.new
66
116
  rtn.set_bits!(@bits)
117
+ rtn.entropy = entropy
67
118
  rtn
68
119
  end
69
120
 
@@ -213,6 +264,10 @@ class Set
213
264
  self
214
265
  end
215
266
 
267
+ def add(items)
268
+ dup.add!(items)
269
+ end
270
+
216
271
  def empty?
217
272
  @bits == 0
218
273
  end
@@ -275,10 +330,47 @@ class Set
275
330
  rtn
276
331
  end
277
332
 
278
- def to_a
333
+ def to_a(int = true)
279
334
  rtn = []
280
335
  each_member do |num|
281
- rtn.push num
336
+ rtn.push int ? num : num.chr
337
+ end
338
+ rtn
339
+ end
340
+
341
+ def to_ra(int=true, th=3)
342
+ raise "Threshold too low" unless th >= 2
343
+ rtn = []
344
+ cnt = 0
345
+ last = -100
346
+ flag = false
347
+ th -= 1
348
+ each_member do |num|
349
+ # byebug unless int
350
+ rtn.push int ? num : num.chr
351
+ if ((last+1)==num)
352
+ # byebug if cnt.nil?
353
+ cnt += 1
354
+ flag = cnt >= th
355
+ elsif flag
356
+ save = rtn.pop
357
+ tmp = rtn.pop(cnt+1)
358
+ range = (tmp.first)..(tmp.last)
359
+ rtn.push range
360
+ rtn.push save
361
+ cnt = 0
362
+ last = -100
363
+ flag = false
364
+ else
365
+ cnt = 0
366
+ end
367
+ last = num
368
+ end
369
+ #byebug
370
+ if flag # convert final range
371
+ tmp = rtn.pop(cnt+1)
372
+ range = (tmp.first)..(tmp.last)
373
+ rtn.push range
282
374
  end
283
375
  rtn
284
376
  end
data/setfu.gemspec CHANGED
@@ -16,7 +16,7 @@ Member elements can be represented as positive small integers, or characters.
16
16
  Sets can be constructed with integers, strings, characters, ranges, and arrays.
17
17
  When characters are used, the ordinate value sets the element bit of the internal Bignum.}
18
18
  spec.summary = %q{Set class}
19
- spec.homepage = ""
19
+ spec.homepage = "http://bdlsys.com/gems/setfu.html"
20
20
  spec.license = "MIT"
21
21
 
22
22
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setfu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Colvin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,7 @@ files:
88
88
  - lib/setfu.rb
89
89
  - lib/setfu/version.rb
90
90
  - setfu.gemspec
91
- homepage: ''
91
+ homepage: http://bdlsys.com/gems/setfu.html
92
92
  licenses:
93
93
  - MIT
94
94
  metadata: {}