Module: Transender

Defined in:
lib/transender.rb

Defined Under Namespace

Classes: Ji

Constant Summary collapse

LIBPATH =

:stopdoc:

::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
V =
YAML.load_file(File.join(File.dirname(__FILE__), %w[.. VERSION.yml]))
VERSION =
"#{V[:major]}.#{V[:minor]}.#{V[:patch]}"

Class Method Summary collapse

Class Method Details

.extract_filename(url) ⇒ Object

for 67_PennyStocksFree/KitschBlogFree/Classes/Tests/ResourceTest.h“ result is: ResurceTest.h



73
74
75
# File 'lib/transender.rb', line 73

def self.extract_filename(url)
  url.split('/').last
end

.extract_name(url) ⇒ Object

for 67_PennyStocksFree/KitschBlogFree/Classes/Tests/ResourceTest.h“ result is: ResurceTest



67
68
69
# File 'lib/transender.rb', line 67

def self.extract_name(url)
  url.split('/').last.split('.').first
end

.extract_path(url) ⇒ Object

for 67_PennyStocksFree/KitschBlogFree/Classes/Tests/ResourceTest.h“ result is: 67_PennyStocksFree/KitschBlogFree/Classes/Tests



79
80
81
# File 'lib/transender.rb', line 79

def self.extract_path(url)
  url.split('/')[0..-2].join('/')
end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



23
24
25
# File 'lib/transender.rb', line 23

def self.libpath( *args )
  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



31
32
33
# File 'lib/transender.rb', line 31

def self.path( *args )
  args.empty? ? PATH : ::File.join(PATH, args.flatten)
end

.replace_in_file(in_file, old, fresh, out_file) ⇒ Object

replaces all ‘old’ strings with ‘fresh’ strings



49
50
51
# File 'lib/transender.rb', line 49

def self.replace_in_file( in_file, old, fresh, out_file)
   `sed 's/#{old}/#{fresh}/g' <'#{in_file}' >'#{out_file}'`
end

.replace_strings_in_file(old, fresh, filename) ⇒ Object



53
54
55
56
57
58
# File 'lib/transender.rb', line 53

def self.replace_strings_in_file(old, fresh, filename)
  temp = "#{filename}.temp"
  FileUtils.mv filename, temp
  Transender.replace_in_file(temp, old, fresh, filename)
  FileUtils.rm temp
end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



40
41
42
43
44
45
46
# File 'lib/transender.rb', line 40

def self.require_all_libs_relative_to( fname, dir = nil )
  dir ||= ::File.basename(fname, '.*')
  search_me = ::File.expand_path(
      ::File.join(::File.dirname(fname), dir, '**', '*.rb'))

  Dir.glob(search_me).sort.each {|rb| require rb}
end

.versionObject

Returns the version string for the library.



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

def self.version
  VERSION
end

.zip_dir(dir, out_file) ⇒ Object



60
61
62
63
# File 'lib/transender.rb', line 60

def self.zip_dir(dir, out_file)
  `tar cvfz '#{out_file}' '#{dir}'`
  out_file
end