qman 0.0.2 → 0.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/qman +102 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf5f32c19e378fc755053b09de5f312d1d5b5f71
4
- data.tar.gz: 5d5a3d0ad44154199871a5461a5510bf6e24942c
3
+ metadata.gz: 39020bb45440170f34a28a085026ed013f94c494
4
+ data.tar.gz: 9c91d6b559267e453cdd2ab787a730d7e0fba2ac
5
5
  SHA512:
6
- metadata.gz: 8ece25b35c86d245223d81ccc3bb878e55bc36bd4a6287518da2c3ee35c6583953ffd769bf449fe0333902ce018cad5d58c2b6ec1a9004251270fe6079c811be
7
- data.tar.gz: dde64336543a34d9f4146961acf879bd3ec18e54c7c16f340716313c51888bfce83a1bdd9032407445d51e949f623af5d2a7f32084011afe1ecc0888a2af8abe
6
+ metadata.gz: a318150529536982de3d670f550fa204fbca2b0ed100576141b86a0c8a8bd20663bb6b1631807981bcb6f46890f5c80a4d00db84ba09d75b6a10746c0b1d9835
7
+ data.tar.gz: a6c51f25a025c3e0411498e040bb11d4c273ea4474c410f1a890c336260145e9880158140b10bea94c82a19c3bab304bf802ffbdcf6677863f3a96ff6dbaecc2
data/bin/qman CHANGED
@@ -5,9 +5,108 @@ require 'git'
5
5
  require 'logger'
6
6
  require 'open-uri'
7
7
  require 'json'
8
- require_relative 'mod'
9
- require_relative 'settings'
10
- require_relative 'custom_helpers'
8
+
9
+ require 'git'
10
+ require 'fileutils'
11
+
12
+ class Settings
13
+ QMAN_CONFIG_DIR = File.expand_path "~/.qman"
14
+ QMAN_CONFIG_FILEPATH = QMAN_CONFIG_DIR + "/repo_url"
15
+ QMAN_DATA_DIRNAME = "data"
16
+
17
+ def repo_path
18
+ QMAN_CONFIG_DIR + "/" + QMAN_DATA_DIRNAME
19
+ end
20
+
21
+ attr_accessor :repo_url
22
+
23
+ def initialize
24
+ if File.exists? QMAN_CONFIG_FILEPATH
25
+ @repo_url = File.readlines(QMAN_CONFIG_FILEPATH).first.chomp
26
+ else
27
+ first_time_config
28
+ end
29
+ end
30
+
31
+ def first_time_config
32
+ @repo_url = get_first_time_repo_url
33
+ while not validate_repo_url(repo_url)
34
+ puts "Repo invalid. Retry:"
35
+ @repo_url = STDIN.gets
36
+ @repo_url = repo_url.chomp
37
+ end
38
+
39
+ FileUtils.mkdir_p(QMAN_CONFIG_DIR)
40
+ File.open(QMAN_CONFIG_FILEPATH, 'w') { |file| file.write(@repo_url) }
41
+
42
+ # Clone the repository
43
+ g = Git.clone(@repo_url, QMAN_DATA_DIRNAME, :path => QMAN_CONFIG_DIR)
44
+ if g.nil?
45
+ puts "Could not clone the repo."
46
+ end
47
+ end
48
+
49
+ def get_first_time_repo_url
50
+ puts "Welcome! This is the first time you run qman."
51
+ puts "Please inform the repo to be used (you can create a new one for free at github.com):"
52
+ repo_url = STDIN.gets
53
+ repo_url = repo_url.chomp
54
+ end
55
+
56
+ def validate_repo_url(url)
57
+ return true
58
+ end
59
+ end
60
+
61
+ def print_mod
62
+ '####################################################' + "\n" +
63
+ ' ________ _____ ______ ________ ________ ' + "\n" +
64
+ ' |\ __ \|\ _ \ _ \|\ __ \|\ ___ \ ' + "\n" +
65
+ ' \ \ \|\ \ \ \\\\\__\ \ \ \ \|\ \ \ \\\\ \ \ ' + "\n" +
66
+ ' \ \ \\\\\ \ \ \\|__|\\ \ \ \ __ \ \ \\\\ \ \ ' + "\n" +
67
+ ' \ \ \\\\\ \ \ \ \ \ \ \ \ \ \ \ \\\\ \ \ ' + "\n" +
68
+ ' \ \_____ \ \__\ \ \__\ \__\ \__\ \__\\\\ \__\ ' + "\n" +
69
+ ' \|___| \__\|__| \|__|\|__|\|__|\|__| \|__| ' + "\n" +
70
+ ' \|__| ' + "\n" +
71
+ '####################################################' + "\n\n" +
72
+ 'Collaborative MAN pages ' + "\n\n"
73
+ end
74
+
75
+ def print_no_results(query)
76
+ "( Sorry, I could no find qman files related to #{query} )" + "\n\n" +
77
+ ' o ^__^ ' + "\n" +
78
+ ' o (oo)\_______ ' + "\n" +
79
+ ' (__)\ )\/\ ' + "\n" +
80
+ ' ||----w | ' + "\n" +
81
+ ' || || ' + "\n"
82
+
83
+ end
84
+
85
+ def levenshtein_distance(s, t)
86
+ m = s.length
87
+ n = t.length
88
+ return m if n == 0
89
+ return n if m == 0
90
+ d = Array.new(m+1) {Array.new(n+1)}
91
+
92
+ (0..m).each {|i| d[i][0] = i}
93
+ (0..n).each {|j| d[0][j] = j}
94
+ (1..n).each do |j|
95
+ (1..m).each do |i|
96
+ d[i][j] = if s[i-1] == t[j-1]
97
+ d[i-1][j-1]
98
+ else
99
+ [ d[i-1][j]+1,
100
+ d[i][j-1]+1,
101
+ d[i-1][j-1]+1,
102
+ ].min
103
+ end
104
+ end
105
+ end
106
+ d[m][n]
107
+ end
108
+
109
+
11
110
 
12
111
  ARGV << '-h' if ARGV.empty?
13
112
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Márcio PaivaMatheus Barros