Module: Path
- Defined in:
- lib/rbbt/resource/path/refactor.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all_fields ⇒ Object
-
#basename ⇒ Object
def index(options = {}) TSV.index(self.produce, **options) end.
- #doc_file(relative_to = 'lib') ⇒ Object
- #fields ⇒ Object
- #identifier_file_path ⇒ Object
- #identifier_files ⇒ Object
- #keys(field = 0, sep = "\t") ⇒ Object
- #pipe_to(cmd, options = {}) ⇒ Object
- #pos_index(pos, options = {}) ⇒ Object
- #range_index(start, eend, options = {}) ⇒ Object
- #remove_extension(new_extension = nil) ⇒ Object
- #replace_extension(new_extension = nil, multiple = false) ⇒ Object
- #set_extension(new_extension = nil) ⇒ Object
- #source_for_doc_file(relative_to = 'lib') ⇒ Object
- #to_yaml(*args) ⇒ Object
-
#traverse(options = {}, &block) ⇒ Object
def tsv_options(options = {}) self.open do |stream| TSV::Parser.new(stream, options).options end end.
- #yaml ⇒ Object
Class Method Details
.get_extension(path) ⇒ Object
122 123 124 |
# File 'lib/rbbt/resource/path/refactor.rb', line 122 def self.get_extension(path) path.match(/\.([^\.\/]{1,5})$/)[1] end |
Instance Method Details
#all_fields ⇒ Object
90 91 92 93 94 |
# File 'lib/rbbt/resource/path/refactor.rb', line 90 def all_fields self.open do |stream| TSV.parse_header(stream)["all_fields"] end end |
#basename ⇒ Object
33 34 35 |
# File 'lib/rbbt/resource/path/refactor.rb', line 33 def basename Path.setup(File.basename(self), self.resource, self.pkgdir) end |
#doc_file(relative_to = 'lib') ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/rbbt/resource/path/refactor.rb', line 138 def doc_file(relative_to = 'lib') if located? lib_dir = Path.caller_lib_dir(self, relative_to) relative_file = File.join( 'doc', self.sub(lib_dir,'')) Path.setup File.join(lib_dir, relative_file) , @pkgdir, @resource else Path.setup File.join('doc', self) , @pkgdir, @resource end end |
#fields ⇒ Object
86 87 88 |
# File 'lib/rbbt/resource/path/refactor.rb', line 86 def fields TSV.parse_header(self.open).fields end |
#identifier_file_path ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/rbbt/resource/path/refactor.rb', line 96 def identifier_file_path if self.dirname.identifiers.exists? self.dirname.identifiers else nil end end |
#identifier_files ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/rbbt/resource/path/refactor.rb', line 104 def identifier_files if identifier_file_path.nil? [] else [identifier_file_path] end end |
#keys(field = 0, sep = "\t") ⇒ Object
60 61 62 |
# File 'lib/rbbt/resource/path/refactor.rb', line 60 def keys(field = 0, sep = "\t") Open.read(self.produce.find).split("\n").collect{|l| next if l =~ /^#/; l.split(sep, -1)[field]}.compact end |
#pipe_to(cmd, options = {}) ⇒ Object
70 71 72 |
# File 'lib/rbbt/resource/path/refactor.rb', line 70 def pipe_to(cmd, = {}) CMD.cmd(cmd, {:in => self.open, :pipe => true}.merge()) end |
#pos_index(pos, options = {}) ⇒ Object
78 79 80 |
# File 'lib/rbbt/resource/path/refactor.rb', line 78 def pos_index(pos, = {}) TSV.pos_index(self.produce, pos, ) end |
#range_index(start, eend, options = {}) ⇒ Object
74 75 76 |
# File 'lib/rbbt/resource/path/refactor.rb', line 74 def range_index(start, eend, = {}) TSV.range_index(self.produce, start, eend, ) end |
#remove_extension(new_extension = nil) ⇒ Object
117 118 119 |
# File 'lib/rbbt/resource/path/refactor.rb', line 117 def remove_extension(new_extension = nil) self.sub(/\.[^\.\/]{1,5}$/,'') end |
#replace_extension(new_extension = nil, multiple = false) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rbbt/resource/path/refactor.rb', line 126 def replace_extension(new_extension = nil, multiple = false) if String === multiple new_path = self.sub(/(\.[^\.\/]{1,5})(.#{multiple})?$/,'') elsif multiple new_path = self.sub(/(\.[^\.\/]{1,5})+$/,'') else new_path = self.sub(/\.[^\.\/]{1,5}$/,'') end new_path = new_path + "." + new_extension.to_s self.annotate(new_path) end |
#set_extension(new_extension = nil) ⇒ Object
112 113 114 115 |
# File 'lib/rbbt/resource/path/refactor.rb', line 112 def set_extension(new_extension = nil) new_path = self + "." + new_extension.to_s self.annotate(new_path) end |
#source_for_doc_file(relative_to = 'lib') ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/rbbt/resource/path/refactor.rb', line 148 def source_for_doc_file(relative_to = 'lib') if located? lib_dir = Path.caller_lib_dir(Path.caller_lib_dir(self, 'doc'), relative_to) relative_file = self.sub(/(.*\/)doc\//, '\1').sub(lib_dir + "/",'') file = File.join(lib_dir, relative_file) if not File.exist?(file) file= Dir.glob(file.sub(/\.[^\.\/]+$/, '.*')).first end Path.setup file, @pkgdir, @resource else relative_file = self.sub(/^doc\//, '\1') if not File.exist?(relative_file) relative_file = Dir.glob(relative_file.sub(/\.[^\.\/]+$/, '.*')).first end Path.setup relative_file , @pkgdir, @resource end end |
#to_yaml(*args) ⇒ Object
82 83 84 |
# File 'lib/rbbt/resource/path/refactor.rb', line 82 def to_yaml(*args) self.to_s.to_yaml(*args) end |
#traverse(options = {}, &block) ⇒ Object
56 57 58 |
# File 'lib/rbbt/resource/path/refactor.rb', line 56 def traverse( = {}, &block) TSV::Parser.traverse(self.open, , &block) end |
#yaml ⇒ Object
64 65 66 67 68 |
# File 'lib/rbbt/resource/path/refactor.rb', line 64 def yaml self.open do |f| YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(f) : YAML.load(f) end end |