dtcterm 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/bin/dtcterm +8 -0
- data/lib/dtcterm.rb +68 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 023acd8ccbe9f7c99e94c7595280cc48ad64a084
|
4
|
+
data.tar.gz: e3af934e16a44283a054917eb14f43a38e327e04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d2e8b1dc788da1492b9fa151d95e7912a252b97dd5604467f954f6d98f8137f969f573bae959b0746e3b86d46d368096bfb85f43da9e0e0fc9fb4b3a2d6bf8b
|
7
|
+
data.tar.gz: 371a517345cc0b1f3b6cf0fc7c537c0b00ee1d2fd64f62dd366038fef4f7deddf31f50e2a4ed5c4cced03761a93d929132c1ff0379e6529ba2c21c2fcd4e1c5e
|
data/bin/dtcterm
CHANGED
data/lib/dtcterm.rb
CHANGED
@@ -27,38 +27,92 @@ module Dtcterm
|
|
27
27
|
DTC_RANDOM_POSITIVE_URL = "http://danstonchat.com/random0.html"
|
28
28
|
DTC_TOP_URL = "http://danstonchat.com/top50.html"
|
29
29
|
|
30
|
+
DEFAULT_COLOR = "37"
|
31
|
+
|
32
|
+
|
30
33
|
def version
|
31
|
-
'0.3.
|
34
|
+
'0.3.1'
|
32
35
|
end
|
33
36
|
|
34
37
|
|
35
|
-
|
38
|
+
# Class that contains every usefull information for a quote
|
36
39
|
class Quote
|
40
|
+
|
41
|
+
# Quote id.
|
37
42
|
attr_accessor :id
|
43
|
+
|
44
|
+
# Link to the quote.
|
38
45
|
attr_accessor :link
|
46
|
+
|
47
|
+
# The text as an array of [user, text]
|
39
48
|
attr_accessor :quote
|
40
49
|
|
50
|
+
# Usernames existing in the quote
|
51
|
+
attr_accessor :usernames
|
52
|
+
|
53
|
+
|
41
54
|
def initialize
|
42
55
|
@id = 0
|
43
56
|
@link = ""
|
44
57
|
@quote = Array.new { Array.new(2) }
|
58
|
+
@usernames = {}
|
59
|
+
|
60
|
+
@colors = {
|
61
|
+
"red" => { :syn => "31", :set => false },
|
62
|
+
"green" => { :syn => "32", :set => false },
|
63
|
+
"yellow" => { :syn => "33", :set => false },
|
64
|
+
"blue" => { :syn => "34", :set => false },
|
65
|
+
"purple" => { :syn => "35", :set => false },
|
66
|
+
"cyan" => { :syn => "36", :set => false }
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
# Return the first color non set.
|
71
|
+
# If no colors available, then it returns the default one.
|
72
|
+
def self.get_color
|
73
|
+
@colors.each {
|
74
|
+
|key, val|
|
75
|
+
(val[:set] = true; return val[:syn]) unless val[:set]
|
76
|
+
}
|
77
|
+
DEFAULT_COLOR
|
45
78
|
end
|
46
79
|
|
47
|
-
|
48
|
-
|
80
|
+
# Add the user to the usernames list.
|
81
|
+
#
|
82
|
+
# Arguments:
|
83
|
+
# colors: (string)
|
84
|
+
def self.add_user(user)
|
85
|
+
@usernames[user] = get_color unless @usernames.has_key?(user)
|
49
86
|
end
|
50
87
|
|
88
|
+
# Colorize the text from the given color
|
89
|
+
#
|
90
|
+
# Arguments:
|
91
|
+
# colors: (string)
|
92
|
+
# text: (string)
|
93
|
+
def self.colorize(color, text)
|
94
|
+
"\e[#{color}m#{text}\e[0m"
|
95
|
+
end
|
96
|
+
|
97
|
+
# Display the quote to stdout
|
51
98
|
def display
|
52
99
|
print "Quote ##{id}\n"
|
53
100
|
print "Link: #{link}\n"
|
54
101
|
@quote.each do |item|
|
55
|
-
|
102
|
+
add_user(item[0])
|
103
|
+
print "#{$using_color \
|
104
|
+
? colorize(@usernames[item[0]], item[0]) \
|
105
|
+
: item[0]} #{item[1]}\n"
|
56
106
|
end
|
57
107
|
end
|
58
108
|
end
|
59
109
|
|
60
110
|
|
61
111
|
|
112
|
+
# Open the html page. Exit the script if it can't reach the server.
|
113
|
+
#
|
114
|
+
# Arguments:
|
115
|
+
# url: (string)
|
62
116
|
def get_page_html(url)
|
63
117
|
begin
|
64
118
|
Nokogiri::HTML(open(url))
|
@@ -68,6 +122,10 @@ module Dtcterm
|
|
68
122
|
end
|
69
123
|
end
|
70
124
|
|
125
|
+
# Give the quote list from the html page.
|
126
|
+
#
|
127
|
+
# Arguments:
|
128
|
+
# html: (string)
|
71
129
|
def get_quote_list(html)
|
72
130
|
quote_list = Array.new
|
73
131
|
|
@@ -105,6 +163,10 @@ module Dtcterm
|
|
105
163
|
quote_list
|
106
164
|
end
|
107
165
|
|
166
|
+
# Display a list of quote
|
167
|
+
#
|
168
|
+
# Arguments:
|
169
|
+
# quote_list: (array)
|
108
170
|
def display_quote_list(quote_list)
|
109
171
|
quote_list.each do |quote|
|
110
172
|
quote.display
|
@@ -112,9 +174,8 @@ module Dtcterm
|
|
112
174
|
end
|
113
175
|
end
|
114
176
|
|
115
|
-
|
116
|
-
|
117
177
|
def main(options)
|
178
|
+
# Exit the program if a choice has already been made.
|
118
179
|
def self.quote_already_set
|
119
180
|
unless $dtc_choice.empty?
|
120
181
|
puts("Un choix de quote a déjà été fait.")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtcterm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loïc Runarvot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|