mspassov_search_gem 1.0.3

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDY4MGRmYjU2NGE5M2YyMTIzMWZmMTQ5NTBhYmQ4NTNiMTA3Y2YxZA==
5
+ data.tar.gz: !binary |-
6
+ M2EyN2VkY2U3YzQ0NjdiNTEyOGEwYTYzYjEzMGEyMTZiNWQzZTRhMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YmFmNjFlZDkyMTYyMGU2NGE5Njg0OTJiNjlkNjgzNmE0OTI0OGE0MGFiOWVi
10
+ MDgyZDlkZDJjNWNmYzg4M2M3YTcyNDMwZThiZjA3ZjVlOGQzMDEwOGU4NGMy
11
+ ZmYxYjk5NTdjOTVkNmY1ZDUyN2UxZTE0YTgwZDBjNTU1ZTFkOTE=
12
+ data.tar.gz: !binary |-
13
+ ZGFhNTFmMzUzOTMyZTYwZGU5NTM5ODQ5OGZjZTAwYmZiMzBlY2YwOGFlMjU0
14
+ MmU4MzgzZTZiMGI0YTU2ZDg0ZWRkMGI2MjIxZDc0YTAzODkyZWRhOGZmZDg4
15
+ MjMwYWY0ZWFkMGRhYjYxZDA4MjcxMDUwYjgxYmUwZTg5MDY2NDg=
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'search_gem'
3
+ puts "search_gem script executing"
4
+ puts ARGV[0]
5
+
6
+ search = SearchGem::MainClass.new
7
+ search.start
8
+ #puts TestGem::MyFile.first(ARGV[0])
9
+ #puts TestGem::MyFile.last(ARGV[0])
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path("../search_gem", __FILE__)
2
+
3
+ require 'version'
4
+ require 'main_class'
5
+
6
+ module SearchGem
7
+
8
+ puts "module SearchGem defined"
9
+
10
+ end
@@ -0,0 +1,125 @@
1
+ module SearchGem
2
+
3
+ require 'date'
4
+ require 'time'
5
+
6
+ class MainClass
7
+
8
+ def initialize
9
+ @index_performed = false
10
+ @index=[]
11
+ @search_input =""
12
+ #@time_now = Time.now
13
+ end
14
+
15
+ def index
16
+ puts "Indexing..."
17
+ @index_performed = true
18
+ @time_of_current_index = Time.now
19
+ #Dir.chdir navigates to the drive root
20
+ Dir.chdir
21
+ #Dir.chroot
22
+ puts "Indexing finished"
23
+ @index = Dir.glob(File.join("**","*.*"))
24
+ end
25
+
26
+ def search file_to_find
27
+ puts "Checking for files with names containing -> " + file_to_find
28
+ @index.select{|file| file.rpartition("/")[2].downcase.include? file_to_find.downcase }
29
+ end
30
+
31
+ def show_search_results
32
+ counter = 0
33
+ puts "Starting search"
34
+ search(@search_input).each do |f|
35
+ puts f
36
+ counter += 1
37
+ end
38
+ puts "======================================================="
39
+ puts "Search finished - found #{counter} files containing '#{@search_input}' in their name."
40
+ puts "======================================================="
41
+ end
42
+
43
+ def start
44
+ puts "Starting application. Please wait..."
45
+ puts "Looking for existing index..."
46
+
47
+ if(read_index)
48
+ puts "Index loaded"
49
+ else
50
+ index
51
+ end
52
+
53
+ puts "Please enter file name or file extension to search for."
54
+ puts "To quit the program enter Q at the console."
55
+ @search_input = gets.chomp
56
+
57
+ #main loop it expects search term or "Q" for exit
58
+ until @search_input.downcase.eql? "q"
59
+ if(@search_input.downcase.eql? "h")
60
+ puts help
61
+ else
62
+ if @index_performed
63
+ show_search_results
64
+ else
65
+ index
66
+ show_search_results
67
+ end
68
+ end
69
+ puts "Please enter file name or file extension to search for or 'Q' to exit."
70
+ @search_input = gets.chomp
71
+ end
72
+ save_index
73
+ puts "Exiting application..."
74
+ "Exiting application..."
75
+ end
76
+
77
+ def more_than_five_minutes_old(start_time, end_time)
78
+ (end_time - start_time)/60 > 5
79
+ end
80
+
81
+ def read_index
82
+ index_number=0
83
+ @file_name = Dir.pwd + "/" + "Index.txt"
84
+ #puts @file_name
85
+ if(File.exists?(@file_name))
86
+ IO.foreach(@file_name) do |line|
87
+ if(index_number == 0)
88
+ #puts "This is the first line of the file" + line
89
+ @time_of_current_index = Time.parse(line)
90
+ if(more_than_five_minutes_old(@time_of_current_index,Time.now))
91
+ index
92
+ return true
93
+ end
94
+ index_number += 1
95
+ else
96
+ @index<<line
97
+ index_number += 1
98
+ end
99
+ end
100
+ @index_performed = true
101
+ return true
102
+ else
103
+ @index_performed = false
104
+ false
105
+ end
106
+ end
107
+
108
+ def save_index
109
+ puts "Saving index"
110
+ #puts @file_name
111
+ string_to_save = Time.now.to_s + "\n" + @index.join("\n")
112
+
113
+ if(File.exists?(@file_name))
114
+ File.delete(@file_name)
115
+ end
116
+ File.open(@file_name,"w") {|file| file.write string_to_save }
117
+ end
118
+
119
+ def help
120
+ "Enter search pattern without using quotes - e.g. (document.txt)
121
+ To quit the application type 'q' or 'Q'
122
+ To display help information type 'h' or 'H'"
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,9 @@
1
+ module SearchGem
2
+
3
+ puts "file version.rb required"
4
+
5
+ VERSION = "1.0.3"
6
+
7
+
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mspassov_search_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Miroslav Spassov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem to explain how to make gems
14
+ email: miroslavspassov@yahoo.com
15
+ executables:
16
+ - search_gem
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/search_gem.rb
21
+ - lib/search_gem/version.rb
22
+ - lib/search_gem/main_class.rb
23
+ - bin/search_gem
24
+ homepage: http://rubygems.org/gems/mspassov_test_gem
25
+ licenses: []
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Making a Search Gem
47
+ test_files: []
48
+ has_rdoc: