manr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/manr +2 -64
  2. data/lib/manr.rb +69 -1
  3. data/lib/manr/version.rb +1 -1
  4. metadata +4 -4
data/bin/manr CHANGED
@@ -1,68 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- require 'find'
3
-
4
- module Manr
5
- @@list = []
6
- @@cache_path = File.expand_path("~/.manr/cache")
7
- @@allowed_mans = ["man1", "man5", "man6", "man8"]
8
-
9
- def self.convert_path(path)
10
- path = path.split("/")
11
- path = path[path.size-1]
12
- path = path.match(/([^.]+)/)
13
- path[0]
14
- end
15
-
16
- def self.check_allowed_man(path)
17
- ok = false
18
-
19
- @@allowed_mans.each do |m|
20
- ok = ok || path.include?(m)
21
- end
22
-
23
- ok
24
- end
25
-
26
- def self.check_cache
27
- File.exists?(@@cache_path)
28
- end
29
-
30
- def self.generate_cache
31
- puts "Generating new cache..."
32
- dir = "/usr/share/man"
33
- @@list = []
34
-
35
- Find.find(dir) do |path|
36
- unless FileTest.directory?(path)
37
- @@list += [convert_path(path)] if path.match(/gz$/) && check_allowed_man(path)
38
- end
39
- end
40
-
41
- @@list.uniq!
42
- @@list.sort!
43
-
44
- dir_path = File.expand_path("~/.manr")
45
-
46
- Dir.mkdir(dir_path) unless File.directory?(dir_path)
47
-
48
- File.open(@@cache_path, 'w') { |f| f.write(@@list.join("\n")) }
49
- end
50
-
51
- def self.load_cache
52
- @@list = []
53
-
54
- File.open(@@cache_path, "r") do |infile|
55
- while (line = infile.gets)
56
- @@list += [line]
57
- end
58
- end
59
- end
60
-
61
- def self.random_manual
62
- man = @@list[rand(@@list.size)]
63
- exec "man #{man}"
64
- end
65
- end
2
+ require 'rubygems'
3
+ require 'manr'
66
4
 
67
5
  Manr.check_cache ? Manr.load_cache : Manr.generate_cache
68
6
  Manr.random_manual
@@ -1,2 +1,70 @@
1
+ require 'find'
1
2
  module Manr
2
- end
3
+ @@list = []
4
+ @@cache_path = File.expand_path("~/.manr/cache")
5
+ @@allowed_mans = ["man1", "man5", "man6", "man8"]
6
+ @@man_dir = "/usr/share/man"
7
+
8
+ def self.convert_path(path)
9
+ number = path.match(/man([0-9])/)
10
+ number = number[1]
11
+
12
+ path = path.split("/")
13
+ path = path[path.size-1]
14
+ path = path.match(/(.*).[0-9].*.gz/)
15
+ "#{number} #{path[1]}"
16
+ end
17
+
18
+ def self.need_update?
19
+ File.mtime(@@cache_path)+60*60*24*2<Time.now
20
+ end
21
+
22
+ def self.check_allowed_man(path)
23
+ ok = false
24
+
25
+ @@allowed_mans.each do |m|
26
+ ok = ok || path.include?(m)
27
+ end
28
+
29
+ ok
30
+ end
31
+
32
+ def self.check_cache
33
+ File.exists?(@@cache_path) && !need_update?
34
+ end
35
+
36
+ def self.generate_cache
37
+ puts "Generating new cache..."
38
+ @@list = []
39
+
40
+ Find.find(@@man_dir) do |path|
41
+ unless FileTest.directory?(path)
42
+ @@list += [convert_path(path)] if path.match(/gz$/) && check_allowed_man(path)
43
+ end
44
+ end
45
+
46
+ @@list.uniq!
47
+ @@list.sort!
48
+
49
+ dir_path = File.expand_path("~/.manr")
50
+
51
+ Dir.mkdir(dir_path) unless File.directory?(dir_path)
52
+
53
+ File.open(@@cache_path, 'w') { |f| f.write(@@list.join("\n")) }
54
+ end
55
+
56
+ def self.load_cache
57
+ @@list = []
58
+
59
+ File.open(@@cache_path, "r") do |infile|
60
+ while (line = infile.gets)
61
+ @@list += [line]
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.random_manual
67
+ man = @@list[rand(@@list.size)]
68
+ exec "man #{man}"
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module Manr
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Piotr Pawel Debosz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-26 00:00:00 +02:00
18
+ date: 2011-06-28 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21