Sha256: 60a45722c5147941528410c90c56dd7e3dcde64ac9287ab7fbd386cd9508f1e4
Contents?: true
Size: 1.59 KB
Versions: 3
Compression:
Stored size: 1.59 KB
Contents
class Ld::File attr_accessor :path, :base_name, :name, :type def initialize path @path = path @name = File.basename @path @base_name = name.split('.')[0] @type = File.directory?(@path) ? 1 : 0 end def self.open_dir path Ld::File.new path end def brothers father.children end def children(remove = nil) arr = [] Dir.foreach(@path)do |p| removes = ['.','..','.DS_Store'] removes << remove if remove if !removes.include?(p) arr << Ld::File.new("#{@path}/#{p}") end end arr.sort!{|a,b| b.type-a.type} arr end def father arr = @path.split('/') arr.pop Ld::File.new(arr.join('/')) end def find name name = name.to_s children.each do |f| if f.name == name return f end end return nil end def read File.open(@path).read end def readlines File.open(@path).readlines end def where regexp arr = [] iter_search regexp, arr arr end def search regexp arr = [] iter_search regexp, arr arr end def iter_search regexp, arr children.each do |f| if f.type == 1 f.iter_search regexp, arr end if f.name.match(regexp) arr << f end end self end def iter arr children.each do |f| if f.type == 1 f.iter arr end arr << f end self end def size File.size path end def lines arr = [] File.new(path).each_line{|l| arr << l } arr end def exist? File.exist? path end def method_missing name find name end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ld-0.1.9 | lib/ld/file.rb |
ld-0.1.8 | lib/ld/file.rb |
ld-0.1.7 | lib/ld/file.rb |