vv 0.0.0.alpha.1 → 0.0.1

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: 4bcfa5a3a0a6024aec90286551d5efebf4f92f2b7d29c81ca84bafaa58b3fa8d
4
- data.tar.gz: 82caa47101ece4903671ecae58194688f781dd943d27636ce80df018bea9b634
3
+ metadata.gz: fe93872b369b2bef0d97aee37de5eb1c695868657bac36a0d092be41796eceaf
4
+ data.tar.gz: f8fd0ef72c7406cd5c1b2e54bf7ac50d402a1784bea259e4c9dba24190fe7b66
5
5
  SHA512:
6
- metadata.gz: bb5a73c6de2c899c41bd96c14846e3702f9cc88aa4065c913ef6e39b47446d69a4f0f1b02a82447d27583fa2c42e19f123a3840e5fc9662e906a31596f2c7b13
7
- data.tar.gz: 751751b4244d15ea1b606f5dfea02c16d6455de53307874e438702d0d0d7b8b092d57a39196ef47b84265864c06924d8cf9a676c97614311f599b046869dfb74
6
+ metadata.gz: 5e1b8989145f69d91378dbefa190a2ddb622fbd663c3d224c87f68d7901994a2a340f2ad18d931ab7d89325a9484e3c7d61adc6fc24316885558847700fd4044
7
+ data.tar.gz: 2f59c921b3cca9a1e8a2920e47fad61585fcf09129aa96ca9bc10685acbbba20614d92b975289b53e5f8a95e27ee4b53045cc3f3e48b83ee58565e0674c51fdc
@@ -0,0 +1,95 @@
1
+ module VV
2
+ module ArrayMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def blank?
17
+ self.size == 0
18
+ end
19
+
20
+ def empty?
21
+ self.blank?
22
+ end
23
+
24
+ def gravify
25
+ self.collect do |elem|
26
+ "`#{elem}`"
27
+ end
28
+ end
29
+
30
+ def gravify!
31
+ self.collect! do |elem|
32
+ "`#{elem}`"
33
+ end
34
+ end
35
+
36
+ def stringify_collection grave: false
37
+ return self.gravify.stringify_collection if grave
38
+
39
+ return String.empty_string if self.blank?
40
+ return self.first if self.size == 1
41
+ return self.join " and " if self.size == 2
42
+
43
+ new_collection = self[0..-3]
44
+ back_fragment = self[-2..-1].join ", and "
45
+ new_collection << back_fragment
46
+ new_collection.join ", "
47
+ end
48
+
49
+ def spaced
50
+ self.join(" ")
51
+ end
52
+
53
+ def format!(other)
54
+ self.spaced.format! other
55
+ end
56
+
57
+ def second
58
+ self[1]
59
+ end
60
+
61
+ def third
62
+ self[2]
63
+ end
64
+
65
+ def fourth
66
+ self[3]
67
+ end
68
+
69
+ def fifth
70
+ self[4]
71
+ end
72
+
73
+ def sixth
74
+ self[5]
75
+ end
76
+
77
+ def seventh
78
+ self[6]
79
+ end
80
+
81
+ def eighth
82
+ self[7]
83
+ end
84
+
85
+ def ninth
86
+ self[8]
87
+ end
88
+
89
+ def tenth
90
+ self[9]
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,22 @@
1
+ module VV
2
+ module FalseMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def to_boolean
17
+ self
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ module Gem
2
+
3
+ # dirname is almost always __dir__
4
+ def require_files pattern, dirname: nil
5
+ dirname ||= \
6
+ File.dirname caller_locations[0].path
7
+
8
+ glob = File.join dirname, pattern
9
+ Gem.find_files(glob).each do |filepath|
10
+ start = dirname.size + 1
11
+ ruby_require_path = filepath[start..-1]
12
+ if block_given?
13
+ yield ruby_require_path
14
+ else
15
+ require ruby_require_path
16
+ end
17
+ end
18
+
19
+ end
20
+ module_function :require_files
21
+
22
+ end
@@ -0,0 +1,42 @@
1
+ module VV
2
+ module HashMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def stringify_keys
17
+ transform_keys{ |key| key.to_s }
18
+ end
19
+
20
+ def stringify_keys!
21
+ transform_keys!{ |key| key.to_s }
22
+ end
23
+
24
+ def transform_keys
25
+ return enum_for(:transform_keys) unless block_given?
26
+ result = self.class.new
27
+ self.each_key do |key|
28
+ result[yield(key)] = self[key]
29
+ end
30
+ result
31
+ end
32
+
33
+ def transform_keys!
34
+ return self.enum_for(:transform_keys!) unless block_given?
35
+ self.keys.each do |key|
36
+ self[yield(key)] = self.delete(key)
37
+ end
38
+ self
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ module VV
2
+ module NilMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def to_boolean
17
+ false
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,72 @@
1
+ module Readline
2
+
3
+ def vv_enabled?
4
+ true
5
+ end
6
+ module_function :vv_enabled?
7
+
8
+ def safe_readline(prompt)
9
+ stty_save = `stty -g`.chomp
10
+ begin
11
+ Readline.readline prompt
12
+ rescue Interrupt
13
+ puts
14
+ system("stty", stty_save)
15
+ exit
16
+ end
17
+ end
18
+ module_function :safe_readline
19
+
20
+ def prompt message, exit_on_exit: true
21
+ message.concat " "
22
+
23
+ input = Readline.safe_readline message
24
+
25
+ if input.nil?
26
+ puts
27
+ exit
28
+ end
29
+
30
+ input.chomp!
31
+
32
+ exit if input == "exit" and exit_on_exit
33
+
34
+ input
35
+ end
36
+ module_function :prompt
37
+
38
+ def prompt_yn(message, default: nil)
39
+ default = true if default == "y" or default == "Y"
40
+ default = false if default == "n" or default == "N"
41
+
42
+ option = case default
43
+ when nil
44
+ "[y/n]"
45
+ when false
46
+ "[y/N]"
47
+ when true
48
+ "[Y/n]"
49
+ end
50
+
51
+ option.prepend " "
52
+ message += option
53
+
54
+ answer = nil
55
+
56
+ loop do
57
+ input = prompt(message)
58
+
59
+ answer = default if input == ""
60
+ answer = true if input == "y" or input == "Y"
61
+ answer = false if input == "n" or input == "N"
62
+
63
+ break unless answer.nil?
64
+
65
+ puts "Unrecognized input. Please enter response again."
66
+ end
67
+
68
+ answer
69
+ end
70
+ module_function :prompt_yn
71
+
72
+ end
@@ -0,0 +1,320 @@
1
+ module VV
2
+ module StringMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ base.extend(SharedInstanceAndClassMethods)
7
+ base.include(SharedInstanceAndClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def vv_included?
13
+ true
14
+ end
15
+
16
+ end
17
+
18
+ module SharedInstanceAndClassMethods
19
+
20
+ def empty_string
21
+ ""
22
+ end
23
+
24
+ def forward_slash
25
+ "/"
26
+ end
27
+
28
+ def dash
29
+ "-"
30
+ end
31
+
32
+ def period
33
+ "."
34
+ end
35
+
36
+ def underscore_character
37
+ "_"
38
+ end
39
+
40
+ # See: `safe_filename?` and `safe_path?` methods
41
+ def safe_filename_characters
42
+ numbers = '0-9'
43
+ lowercase = 'a-z'
44
+ uppercase = 'A-Z'
45
+
46
+ [ dash,
47
+ numbers,
48
+ lowercase,
49
+ uppercase,
50
+ underscore_character,
51
+ period ].join
52
+ end
53
+
54
+ end
55
+
56
+ def blank?
57
+ self == ""
58
+ end
59
+
60
+ def starts_with? *args
61
+ self.start_with?(*args)
62
+ end
63
+
64
+ def ends_with? *args
65
+ self.end_with?(*args)
66
+ end
67
+
68
+ def after(string, safe: true)
69
+ if safe && ! self.starts_with?(string)
70
+ message = "String does not start with #{string}"
71
+ raise RuntimeError, message
72
+ elsif not self.starts_with?(string)
73
+ return self
74
+ end
75
+
76
+ self[string.size..-1]
77
+ end
78
+
79
+ def with_ending(string)
80
+ self.chomp(string) + string
81
+ end
82
+
83
+ def squish!
84
+ self.gsub!(/\A[[:space:]]+/, "")
85
+ self.gsub!(/[[:space:]]+\z/, "")
86
+ self.gsub!(/[[:space:]]+/, " ")
87
+ self
88
+ end
89
+
90
+ def squish
91
+ self.dup.squish!
92
+ end
93
+
94
+ def format!(other)
95
+ mappings = {}
96
+ self.split('#{')[1..-1].map do | token_fragment |
97
+ format_string = token_fragment.split("}").first
98
+ token = format_string.squish
99
+
100
+ value = other.instance_variable_get(token).to_s
101
+ wrapped_format_string = '#{' + format_string + "}"
102
+ mappings[wrapped_format_string] = value
103
+ end
104
+
105
+ response = self.dup
106
+
107
+ mappings.each do |key, value|
108
+ response.gsub! key, value
109
+ end
110
+
111
+ response
112
+ end
113
+
114
+ def matches_glob pattern
115
+ File.fnmatch(pattern, self)
116
+ end
117
+
118
+ def to_regex
119
+ Regexp.new self
120
+ end
121
+
122
+ def to_regex_filter
123
+ regex_string = '[^' + self + ']'
124
+ regex_string.to_regex
125
+ end
126
+
127
+ def to_regexp_filter
128
+ self.to_regex_filter
129
+ end
130
+
131
+ def safe_filename?
132
+ unsafe = self.blank?
133
+ unsafe ||= self.starts_with? period
134
+ unsafe ||= self.starts_with? dash
135
+
136
+ unsafe ||= self.end_with? period
137
+ unsafe ||= self.end_with? dash
138
+
139
+ unsafe ||= self =~ self.safe_filename_characters.to_regex_filter
140
+
141
+ ! unsafe
142
+ end
143
+
144
+ def safe_path?
145
+ separator = File::SEPARATOR
146
+
147
+ unsafe = self.starts_with? separator
148
+ unsafe ||= self.ends_with? separator
149
+ unsafe ||= self.split(separator).map(&:safe_filename?).map(&:!).any?
150
+
151
+ ! unsafe
152
+ end
153
+
154
+ def hex?
155
+ return false if self.blank?
156
+ match_non_hex_digits = /\H/
157
+ !self[match_non_hex_digits]
158
+ end
159
+
160
+ def number?
161
+ return false if self.blank?
162
+ self.gsub(/[^0-9]/, '') == self
163
+ end
164
+
165
+ def readable_number?
166
+ self.readable_to_i
167
+ true
168
+ rescue StandardError => e
169
+ return false if e.message == "String is not a number"
170
+ raise
171
+ end
172
+
173
+ def to_boolean
174
+ _true = self == "true"
175
+ return true if _true
176
+
177
+ _false = self == "false"
178
+ return false if _false
179
+
180
+ message = %w[ Unable to cast supplied string to boolean,
181
+ only `"true"` and `"false"` can be coerced into
182
+ boolean. ].spaced
183
+ raise RuntimeError, message
184
+ end
185
+
186
+ def readable_to_i
187
+ return self.to_i if self.number?
188
+
189
+ valid_postfix = self._numeral_postfixes.include? self.last
190
+ valid_body = self[0...-1].number?
191
+ valid = valid_body && valid_postfix
192
+
193
+ message = "String is not a number"
194
+ raise StandardError, message unless valid
195
+
196
+ self[0...-1].to_i * self._numeral_postfixes[self.last]
197
+ end
198
+
199
+ def _numeral_postfixes
200
+ { k: 1000,
201
+ m: 1000_000,
202
+ b: 1000_000_000,
203
+ t: 1000_000_000_000 }.stringify_keys
204
+ end
205
+
206
+ def insta
207
+ return self if self.starts_with?("@")
208
+ "@#{self}"
209
+ end
210
+
211
+ def to position
212
+ self[0..position]
213
+ end
214
+
215
+ def from position
216
+ self[position..-1]
217
+ end
218
+
219
+ def _ensure_pluralize_available!
220
+ message = "String does not define pluralize."
221
+ pluralize_available = self.respond_to? :pluralize
222
+ raise NotImplementedError, message unless pluralize_available
223
+ end
224
+
225
+ def _ensure_singularize_available!
226
+ message = "String does not define singularize."
227
+ singularize_available = self.respond_to? :singularize
228
+ raise NotImplementedError, message unless singularize_available
229
+ end
230
+
231
+ def plural?(coward: true)
232
+ self._ensure_pluralize_available!
233
+ self._ensure_singularize_available!
234
+
235
+ plural = self == self.pluralize
236
+ return plural if !coward || !plural
237
+
238
+ non_ambiguous = self.pluralize != self.singularize
239
+
240
+ message = \
241
+ "String is ambiguously plural. Cowardly exiting."
242
+ raise RuntimeError, message unless non_ambiguous
243
+
244
+ true
245
+ end
246
+
247
+ def singular?(coward: true)
248
+ self._ensure_pluralize_available!
249
+ self._ensure_singularize_available!
250
+
251
+ singular = self == self.singularize
252
+ return singular if !coward || !singular
253
+
254
+ non_ambiguous = self.pluralize != self.singularize
255
+
256
+ message = \
257
+ "String is ambiguously singular. Cowardly exiting."
258
+ raise RuntimeError, message unless non_ambiguous
259
+
260
+ true
261
+ end
262
+
263
+ def last(limit = 1)
264
+ if limit == 0
265
+ ""
266
+ elsif limit >= size
267
+ self.dup
268
+ else
269
+ self.from(-limit)
270
+ end
271
+ end
272
+
273
+ def first limit=1
274
+ if limit == 0
275
+ ""
276
+ elsif limit >= size
277
+ dup
278
+ else
279
+ to(limit - 1)
280
+ end
281
+ end
282
+
283
+ def second
284
+ self[1]
285
+ end
286
+
287
+ def third
288
+ self[2]
289
+ end
290
+
291
+ def fourth
292
+ self[3]
293
+ end
294
+
295
+ def fifth
296
+ self[4]
297
+ end
298
+
299
+ def sixth
300
+ self[5]
301
+ end
302
+
303
+ def seventh
304
+ self[6]
305
+ end
306
+
307
+ def eighth
308
+ self[7]
309
+ end
310
+
311
+ def ninth
312
+ self[8]
313
+ end
314
+
315
+ def tenth
316
+ self[9]
317
+ end
318
+
319
+ end
320
+ end
@@ -0,0 +1,22 @@
1
+ module VV
2
+ module TrueMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def to_boolean
17
+ self
18
+ end
19
+
20
+ end
21
+
22
+ end
data/lib/vv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VV
2
- VERSION = '0.0.0.alpha.1'
2
+ VERSION = '0.0.1'
3
3
  end
data/lib/vv.rb ADDED
@@ -0,0 +1,27 @@
1
+ require_relative "vv/gem_methods"
2
+
3
+ Gem.require_files "vv/*.rb"
4
+
5
+ class String
6
+ include VV::StringMethods
7
+ end
8
+
9
+ class Hash
10
+ include VV::HashMethods
11
+ end
12
+
13
+ class Array
14
+ include VV::ArrayMethods
15
+ end
16
+
17
+ class TrueClass
18
+ include VV::TrueMethods
19
+ end
20
+
21
+ class FalseClass
22
+ include VV::FalseMethods
23
+ end
24
+
25
+ class NilClass
26
+ include VV::NilMethods
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.alpha.1
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Aysan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2018-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.11'
27
55
  description:
28
56
  email:
29
57
  - zachaysan@gmail.com
@@ -33,8 +61,16 @@ extra_rdoc_files: []
33
61
  files:
34
62
  - LICENSE.txt
35
63
  - README.markdown
64
+ - lib/vv.rb
65
+ - lib/vv/array_methods.rb
66
+ - lib/vv/false_methods.rb
67
+ - lib/vv/gem_methods.rb
68
+ - lib/vv/hash_methods.rb
69
+ - lib/vv/nil_methods.rb
70
+ - lib/vv/readline_methods.rb
71
+ - lib/vv/string_methods.rb
72
+ - lib/vv/true_methods.rb
36
73
  - lib/vv/version.rb
37
- - spec/.gitkeep
38
74
  homepage: https://github.com/zachaysan/vv
39
75
  licenses:
40
76
  - MIT
@@ -50,14 +86,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
86
  version: '0'
51
87
  required_rubygems_version: !ruby/object:Gem::Requirement
52
88
  requirements:
53
- - - ">"
89
+ - - ">="
54
90
  - !ruby/object:Gem::Version
55
- version: 1.3.1
91
+ version: '0'
56
92
  requirements: []
57
93
  rubyforge_project:
58
94
  rubygems_version: 2.7.7
59
95
  signing_key:
60
96
  specification_version: 4
61
97
  summary: Make ruby very v
62
- test_files:
63
- - spec/.gitkeep
98
+ test_files: []
data/spec/.gitkeep DELETED
File without changes