class Tagmv::Tree
Attributes
entries[RW]
Public Class Methods
false_tag_regex()
click to toggle source
# File lib/tagmv/tree.rb, line 23 def self.false_tag_regex # detect when there's a false tag i.e. tag2. in path/to/tag1./not_a_tag/tag2./ /\/.+-\/[^-]+\/.+-/ #/\/(.*[^-]\/|[^\/]{0,1}?-)/ end
file_in_tag_dir()
click to toggle source
# File lib/tagmv/tree.rb, line 37 def self.file_in_tag_dir /.+(\-\/[^\/]+)$/ end
new(entries = [])
click to toggle source
# File lib/tagmv/tree.rb, line 6 def initialize(entries = []) @entries = entries end
path_has_file_regex()
click to toggle source
# File lib/tagmv/tree.rb, line 33 def self.path_has_file_regex /#{tags_in_path_regex}.*[^\-]$/ end
scan_tree_entries()
click to toggle source
# File lib/tagmv/tree.rb, line 46 def self.scan_tree_entries files = Find.find(Filesystem.root).select {|x| x =~ path_has_file_regex }.select {|x| x =~ file_in_tag_dir } tree = Tree.new files.each do |file| next if file =~ false_tag_regex # break when /dev./oh/blah./foo tree.entries << Entry.new(files: [file], tags: tags(file)) end tree end
scan_tree_hash()
click to toggle source
only gets existing tree, doesn't build an accurate tree based on all the tag counts etc.. Find.find('.').select {|x| x =~ /([^/]+/)*([^/]+/)*./.*/} {“dev.”=>{“book.”=>{“javascript.”=>{“Secrets_of_the_Javascript_Ninja.pdf”=>{}}, “ruby.”=>{“rails_antipatterns.pdf”=>{}}}, “ruby.”=>{“oh”=>{}, “tagmv”=>{}}}}
# File lib/tagmv/tree.rb, line 59 def self.scan_tree_hash Dir.chdir(Filesystem.root) # reject /dev-/-, /dev-/j-/ and /dev-/notag/tag- paths = Dir["**/*"].delete_if {|x| /\/(.*[^-]\/|[^\/]{0,1}?-)/ =~ x} paths.inject({}) do |hash,path| tree = hash path.split("/").each do |n| tree[n] ||= {} tree = tree[n] break if n[-1] != "-" end hash end end
Public Instance Methods
tag_counts()
click to toggle source
# File lib/tagmv/tree.rb, line 14 def tag_counts entries.map {|x| x.tags }.flatten.each_with_object(Hash.new(0)) { |word,counts| counts[word] += 1 } end
tag_order()
click to toggle source
# File lib/tagmv/tree.rb, line 18 def tag_order tag_counts.to_a.sort_by{|x| [-x.last, x.first]}.map {|x| x.first } end
with(opts)
click to toggle source
# File lib/tagmv/tree.rb, line 10 def with(opts) entries << Entry.new(opts) end