Module: Ykutils::PathOp

Defined in:
lib/ykutils/pathop.rb

Instance Method Summary collapse

Instance Method Details

#determine_fname_for_update(fname, ext = ".bak") ⇒ Object



15
16
17
# File 'lib/ykutils/pathop.rb', line 15

def determine_fname_for_update(fname, ext = ".bak")
  get_buddy_path(fname, "", ext)
end

#determine_fname_for_update2(fname) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ykutils/pathop.rb', line 19

def determine_fname_for_update2(fname)
  begin
    ctime = File.ctime(fname)
  rescue YkutilsError => e
    puts e
  end
  ctime ||= Time.now
  ary = ctime.to_s.split
  extname = File.extname(fname)
  append = ["", ary[0], ary[1].gsub(":", "-")].join("-")
  get_buddy_path(fname, append, extname)
end

#file_ensure(fname) ⇒ Object



32
33
34
# File 'lib/ykutils/pathop.rb', line 32

def file_ensure(fname)
  File.open(fname, "w").close unless File.exist?(fname)
end

#get_buddy_path(fname, append_name = "", extname = "") ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/ykutils/pathop.rb', line 5

def get_buddy_path(fname, append_name = "", extname = "")
  one_path = Pathname.new(fname).expand_path
  dir_path = one_path.dirname
  base_path = one_path.basename(".*")
  append_name = "-2" unless append_name.empty? || extname.empty?
  extname ||= one_path.extname

  [one_path, dir_path.join(base_path.to_s + append_name + extname)]
end