Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/hook/string.rb
Overview
String helpers
Instance Method Summary collapse
-
#cap ⇒ Object
Capitalize only if no uppercase.
- #cap! ⇒ Object
- #clip ⇒ Object
- #escape_quotes ⇒ Object
- #nil_if_missing ⇒ Object
- #split_hook ⇒ Object
- #split_hooks ⇒ Object
- #valid_hook ⇒ Object
- #valid_hook! ⇒ Object
Instance Method Details
#cap ⇒ Object
Capitalize only if no uppercase
42 43 44 45 46 47 48 |
# File 'lib/hook/string.rb', line 42 def cap if self !~ /[A-Z]/ capitalize else self end end |
#cap! ⇒ Object
50 51 52 |
# File 'lib/hook/string.rb', line 50 def cap! replace cap end |
#clip ⇒ Object
54 55 56 57 58 59 |
# File 'lib/hook/string.rb', line 54 def clip res = `/bin/echo -n #{Shellwords.escape(self)} | pbcopy`.strip raise 'Failed to copy to clipboard' unless res.empty? true end |
#escape_quotes ⇒ Object
61 62 63 |
# File 'lib/hook/string.rb', line 61 def escape_quotes gsub(/"/, '\\"') end |
#nil_if_missing ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/hook/string.rb', line 5 def nil_if_missing if self =~ /missing value/ return nil else self end end |
#split_hook ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/hook/string.rb', line 13 def split_hook elements = split(/\|\|/) { name: elements[0].nil_if_missing, url: elements[1].nil_if_missing, path: elements[2].nil_if_missing } end |
#split_hooks ⇒ Object
22 23 24 |
# File 'lib/hook/string.rb', line 22 def split_hooks split(/\^\^/).map(&:split_hook) end |
#valid_hook ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hook/string.rb', line 26 def valid_hook if File.exist?(self) File.(self) elsif self =~ /^\[.*?\]\((.*?)\)$/ mdlink = $1 mdlink.valid_hook else self end end |
#valid_hook! ⇒ Object
37 38 39 |
# File 'lib/hook/string.rb', line 37 def valid_hook! replace valid_hook end |