andys_convenience_methods 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/andy_convenience.rb +21 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb56a9a80f5a49c10ccfc65553fdb7c7afe31944
4
- data.tar.gz: c2ce31bb25c072860e2d16fd0f950cc5603c2b2a
3
+ metadata.gz: a98e1ab75eddf1f350339dad013e18f835606fa6
4
+ data.tar.gz: 8073016868a5c0f62e6f2f9158559123167623e0
5
5
  SHA512:
6
- metadata.gz: 2b0a3438fcb82879730e3c5d13258d57ee39c9f8a4cdf3d4156200d55302192ba207873bc6cebe4a2537fb43f28537ec88c5d83358546a41eff5f05da618d18e
7
- data.tar.gz: dde421544d90fe334eed591bdba1349dbacc4b593274894b58229c48489618538a2076818cc54d376e8925fe6dc0dfba183c886d49887bbd053051f1c2cef24c
6
+ metadata.gz: dbc30d775cb8344fe4eafb389ceb7db13f3e9016f2baa4d813ea78ca188f35370a49de513a9763fe76f84873569d536527789313021fad9b33be4f9a5673e43a
7
+ data.tar.gz: 9b546ed5fc51e0e62fbe40c8b31cc9a7ba2e708bd291e7f5c4b3508bae7e91719ecfab28efd8ee9ec6ad0dc5d510ca9dfa299e924e7769a26bbd42dac75c41aa
@@ -1,3 +1,5 @@
1
+ require 'securerandom'
2
+
1
3
  class String
2
4
  def to_binary
3
5
  ascii = []
@@ -5,6 +7,13 @@ class String
5
7
  ascii.map{ |n| n.to_binary }.join(' ')
6
8
  end
7
9
 
10
+ def webitize(tag, options = nil)
11
+ if options
12
+ options = ' ' + (options.map {|k, v| "#{k}='#{v}'"}.join(' '))
13
+ end
14
+ "<#{tag}#{options}>#{self}</#{tag}>"
15
+ end
16
+
8
17
  def crunch(str)
9
18
  str.chars.chunk{|s| s}.map(&:first).join
10
19
  end
@@ -37,6 +46,11 @@ class String
37
46
  def idx(coll)
38
47
  coll[self.to_i - 1]
39
48
  end
49
+
50
+ alias_method :strc, :stringcrement
51
+ alias_method :stinc, :increment
52
+ alias_method :idxmt, :indexment
53
+ alias_method :to_web, :webitize
40
54
  end
41
55
 
42
56
  class Integer
@@ -50,6 +64,10 @@ class Integer
50
64
  self.increment(interval, operator, seq).to_s
51
65
  end
52
66
 
67
+ def to_tkn
68
+ SecureRandom.urlsafe_base64(self)
69
+ end
70
+
53
71
  def to_binary
54
72
  final_string = ''
55
73
  bins = binlib.select { |n| n <= self }.reverse
@@ -68,6 +86,9 @@ class Integer
68
86
  final_string
69
87
  end
70
88
 
89
+ alias_method :strc, :stringcrement
90
+ alias_method :inc, :increment
91
+
71
92
  private
72
93
 
73
94
  def binlib
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: andys_convenience_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Rosenberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-20 00:00:00.000000000 Z
11
+ date: 2018-08-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A few convenience methods
14
14
  email: andynaterosenberg@gmail.com