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