tdreyno-s6search 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'readline'
3
+ require File.join(File.dirname(__FILE__), '../lib', 's6search')
3
4
 
4
- class SpinSix
5
- CONFIG = '~/.s6search'
6
- PATHS = ["~/Desktop", "~/Desktop/*", # Local
7
- "/Volumes/Shared/Clients/*/Active"] # Remote
8
-
9
- def self.locate_single(number)
10
- matching_directories = paths.map do |path|
11
- Dir["#{File.expand_path(path)}/#{number}*"]
12
- end.flatten.select do |path|
13
- File.directory? path
14
- end
15
-
16
- case matching_directories.length
17
- when 0:
18
- puts "Could not find project #{number}"
19
- when 1:
20
- open_dirs matching_directories[0]
21
- else
22
- puts "Found multiple projects:"
23
- matching_directories.each_with_index do |dir, i|
24
- parts = dir.split('/').last(2)
25
- print (i+1).to_s.rjust(5) + ": "
26
- print parts[0].rjust(7) + "/"
27
- puts parts[1]
28
- end
29
- puts " *: Open all, s: Skip"
5
+ class SpinSixSearch
6
+ class << self
7
+ def locate_single(number)
8
+ matching_directories = search(number)
9
+
10
+ case matching_directories.length
11
+ when 0:
12
+ puts "Could not find project #{number}"
13
+ when 1:
14
+ open_dirs matching_directories[0]
15
+ else
16
+ puts "Found multiple projects:"
17
+ matching_directories.each_with_index do |dir, i|
18
+ parts = dir.split('/').last(2)
19
+ print (i+1).to_s.rjust(5) + ": "
20
+ print parts[0].rjust(7) + "/"
21
+ puts parts[1]
22
+ end
23
+ puts " *: Open all, s: Skip"
30
24
 
31
- print "Action: "
32
- response = Readline.readline
33
- if response.to_i > 0
34
- open_dirs matching_directories[response.to_i-1]
35
- elsif !%w(s q).include? response
36
- open_dirs *matching_directories
25
+ print "Action: "
26
+ response = Readline.readline
27
+ if response.to_i > 0
28
+ open_dirs matching_directories[response.to_i-1]
29
+ elsif !%w(s q).include? response
30
+ open_dirs *matching_directories
31
+ end
37
32
  end
38
33
  end
39
- end
40
-
41
- def self.locate(numbers)
42
- numbers.uniq.each { |n| locate_single(n) }
43
- end
44
-
45
- def self.paths
46
- @@paths ||= begin
47
- config_file = File.expand_path(CONFIG)
48
- return PATHS unless File.exists?(config_file)
49
-
50
- File.open(config_file) do |f|
51
- @@paths = f.readlines.map { |line| line.chomp }.select{ |path| !path.empty? }
52
- end
53
- @@paths
34
+
35
+ def locate(numbers)
36
+ numbers.uniq.each { |n| locate_single(n) }
37
+ end
38
+
39
+ def search(number)
40
+ Spinsix.search(number).map do |id|
41
+ Spinsix.index[id][:path]
42
+ end.uniq
43
+ end
44
+
45
+ protected
46
+ def open_dirs(*paths)
47
+ paths = paths.map { |p| %Q{"#{p}"} }.join(" ")
48
+ `open #{paths}`
54
49
  end
55
- end
56
-
57
- protected
58
- def self.open_dirs(*paths)
59
- paths = paths.map { |p| %Q{"#{p}"} }.join(" ")
60
- `open #{paths}`
61
50
  end
62
51
  end
63
52
 
64
- SpinSix.locate(ARGV)
53
+ SpinSixSearch.locate(ARGV)
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../lib', 's6search')
3
+
4
+ Spinsix.paths.map do |path|
5
+ Dir["#{path}/[0-9][0-9][0-9][0-9]*"]
6
+ end.flatten.select do |path|
7
+ File.directory? path
8
+ end.each do |path|
9
+ results = []
10
+ Spinsix.index.search_each('path:"' + path + '"') do |id, score|
11
+ results << id
12
+ end
13
+ results.uniq!
14
+
15
+ (2..results.length).each do |i|
16
+ puts "Removing from index #{i}"
17
+ Spinsix.index.delete(results[i-1])
18
+ end
19
+
20
+ next if (results.length > 0)
21
+
22
+ puts "Adding to index: #{path.split('/').last}"
23
+ Spinsix.index << { :path => path, :number => path.split('/').last.split('-').first }
24
+ end
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'ferret'
3
+
4
+ class Spinsix
5
+ CONFIG = '~/.s6search'
6
+ PATHS = ["~/Desktop", "~/Desktop/*", # Local
7
+ "/Volumes/Shared/Clients/*/Active"] # Remote
8
+
9
+ class << self
10
+
11
+ def paths
12
+ @@paths ||= begin
13
+ config_file = file_path('conf')
14
+ return PATHS unless File.exists?(config_file)
15
+
16
+ File.open(config_file) do |f|
17
+ @@paths = f.readlines.map { |line| line.chomp }.select{ |path| !path.empty? }
18
+ end
19
+
20
+ @@paths
21
+ end
22
+ end
23
+
24
+ def index
25
+ @@index ||= Ferret::I.new(:path => file_path('index'))
26
+ end
27
+
28
+ def search(number)
29
+ results = []
30
+ index.search_each('number:"' + number + '"') do |id, score|
31
+ results << id
32
+ end
33
+ results
34
+ end
35
+
36
+ def file_path(name)
37
+ @@files ||= {}
38
+ @@files[name] ||= begin
39
+ config_dir = File.expand_path(CONFIG)
40
+ File.mkdir_p(config_dir) if !File.exists?(config_dir)
41
+ File.join(config_dir, name)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -2,15 +2,14 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{s6search}
5
- s.version = "1.0.1"
5
+ s.version = "1.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Thomas Reynolds"]
9
- s.date = %q{2008-09-25}
10
- s.default_executable = %q{s6search}
9
+ s.date = %q{2008-10-06}
11
10
  s.email = %q{thomas.reynolds@spinsix.com}
12
- s.executables = ["s6search"]
13
- s.files = ["bin/s6search", "s6search.gemspec"]
11
+ s.executables = ["s6search", "s6search-index"]
12
+ s.files = ["bin/s6search", "bin/s6search-index", "lib/s6search.rb", "s6search.gemspec"]
14
13
  s.homepage = %q{http://github.com/tdreyno/s6search}
15
14
  s.require_paths = ["lib"]
16
15
  s.rubygems_version = %q{1.3.0}
@@ -21,11 +20,11 @@ Gem::Specification.new do |s|
21
20
  s.specification_version = 2
22
21
 
23
22
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
24
- s.add_runtime_dependency(%q<thor>, [">= 0"])
23
+ s.add_runtime_dependency(%q<ferret>, [">= 0"])
25
24
  else
26
- s.add_dependency(%q<thor>, [">= 0"])
25
+ s.add_dependency(%q<ferret>, [">= 0"])
27
26
  end
28
27
  else
29
- s.add_dependency(%q<thor>, [">= 0"])
28
+ s.add_dependency(%q<ferret>, [">= 0"])
30
29
  end
31
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdreyno-s6search
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-25 00:00:00 -07:00
13
- default_executable: s6search
12
+ date: 2008-10-06 00:00:00 -07:00
13
+ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: thor
16
+ name: ferret
17
17
  version_requirement:
18
18
  version_requirements: !ruby/object:Gem::Requirement
19
19
  requirements:
@@ -25,12 +25,15 @@ description:
25
25
  email: thomas.reynolds@spinsix.com
26
26
  executables:
27
27
  - s6search
28
+ - s6search-index
28
29
  extensions: []
29
30
 
30
31
  extra_rdoc_files: []
31
32
 
32
33
  files:
33
34
  - bin/s6search
35
+ - bin/s6search-index
36
+ - lib/s6search.rb
34
37
  - s6search.gemspec
35
38
  has_rdoc: false
36
39
  homepage: http://github.com/tdreyno/s6search