Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/hook/string.rb

Overview

String helpers

Instance Method Summary collapse

Instance Method Details

#capObject

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

#clipObject



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_quotesObject



61
62
63
# File 'lib/hook/string.rb', line 61

def escape_quotes
  gsub(/"/, '\\"')
end

#nil_if_missingObject



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_hookObject



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_hooksObject



22
23
24
# File 'lib/hook/string.rb', line 22

def split_hooks
  split(/\^\^/).map(&:split_hook)
end

#valid_hookObject



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.expand_path(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