Class: Cronicle::Utils
- Inherits:
-
Object
- Object
- Cronicle::Utils
- Defined in:
- lib/cronicle/utils.rb
Constant Summary collapse
- IPADDR_REGEXP =
/\A\d+(?:\.\d+){3}\z/
Class Method Summary collapse
- .diff(file1, file2) ⇒ Object
- .regexp_union(list) ⇒ Object
- .remove_prompt!(str) ⇒ Object
- .sed_escape(cmd) ⇒ Object
- .short_hostname(hostname) ⇒ Object
Class Method Details
.diff(file1, file2) ⇒ Object
37 38 39 40 41 |
# File 'lib/cronicle/utils.rb', line 37 def diff(file1, file2) file1 = file1.chomp + "\n" file2 = file2.chomp + "\n" Diffy::Diff.new(file1, file2).to_s(:text) end |
.regexp_union(list) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cronicle/utils.rb', line 3 def regexp_union(list) return nil if list.nil? return list if list.kind_of?(Regexp) list = Array(list) return nil if list.empty? Regexp.union(list.map {|str_or_reg| if str_or_reg.kind_of?(Regexp) str_or_reg else /\A#{str_or_reg}\z/ end }) end |
.remove_prompt!(str) ⇒ Object
33 34 35 |
# File 'lib/cronicle/utils.rb', line 33 def remove_prompt!(str) str.sub!(/\A[^:]*:\s*/, '') end |
.sed_escape(cmd) ⇒ Object
29 30 31 |
# File 'lib/cronicle/utils.rb', line 29 def sed_escape(cmd) cmd.gsub('/', '\\/') end |
.short_hostname(hostname) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/cronicle/utils.rb', line 21 def short_hostname(hostname) if hostname =~ IPADDR_REGEXP hostname else hostname.split('.').first end end |