zypper-onlinesearch 1.0.0 → 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,223 +1,255 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zypper
2
4
  module Onlinesearch
3
-
4
5
  module View
5
-
6
- TYPE_COLORS = { experimental: :yellow, supported: :green, community: :red }
6
+ TYPE_COLORS = { experimental: :yellow, supported: :green, community: :red, unsupported: :bg_red }.freeze
7
7
  SEPARATOR_LENGTH = 100
8
8
 
9
-
9
+ #
10
+ # Cache clean view.
11
+ #
10
12
  class CacheClean
11
13
  def self.reset(size)
12
- puts "Cache cleared! " + size.to_f.to_human.bold.red + ' freed.'
14
+ puts "Cache cleared! #{size.to_f.to_human.bold.red} freed."
13
15
  end
14
16
  end
15
17
 
16
-
17
18
  module Search
18
-
19
+ #
20
+ # Common methods for the search operation.
21
+ #
19
22
  class Common
20
-
21
23
  def self.separator
22
- puts '-' * SEPARATOR_LENGTH
24
+ puts "-" * SEPARATOR_LENGTH
23
25
  end
24
26
 
25
27
  def self.no_packages
26
- puts (' ' * 3) + ' - | No packages found!'
27
- self.separator
28
+ puts "#{" " * 3} - | No packages found!"
29
+ separator
28
30
  end
29
31
 
30
32
  def self.no_compatible_packages
31
- puts (' ' * 3) + ' - | No compatible packages found!'
32
- self.separator
33
+ puts "#{" " * 3} - | No compatible packages found!"
34
+ separator
33
35
  end
34
36
 
35
37
  def self.parameters(args)
36
- puts ''
37
- puts '=' * SEPARATOR_LENGTH
38
- puts 'Parameters: '.bold + 'Engine: ' + args[:engine].to_s.bold.red + ' | ' +
39
- 'Query: ' + args[:query].bold + ' | ' +
40
- 'Cache: ' + (args[:cached] ? "#{'On'.bold.yellow} (#{args[:cache_time] ? args[:cache_time].strftime('%Y-%m-%d %H:%M') : 'Now'})" : 'Off'.bold)
41
- puts '=' * SEPARATOR_LENGTH
38
+ engine = args[:engine].bold.red
39
+ query = args[:query].bold
40
+ cache = if args[:refresh]
41
+ "Off".bold
42
+ elsif args[:cache_time]
43
+ "#{"On".bold.yellow} (#{args[:cache_time].strftime("%Y-%m-%d %H:%M")})"
44
+ else
45
+ "#{"On".bold.yellow} (Now)"
46
+ end
47
+
48
+ puts ""
49
+ puts "=" * SEPARATOR_LENGTH
50
+ puts "#{"Parameters:".bold} Engine: #{engine} | Query: #{query} | Cache: #{cache}"
51
+ puts "=" * SEPARATOR_LENGTH
42
52
  end
43
53
  end
44
54
 
55
+ #
56
+ # Report view for the search operation.
57
+ #
45
58
  class Report < Common
46
-
47
- def self.header(args)
48
- puts ' ' * 3 + ' # | Info '
49
- self.separator
59
+ def self.header(_args)
60
+ puts "#{" " * 3} # | Info"
61
+ separator
50
62
  end
51
63
 
52
64
  def self.package(args)
53
65
  name = args[:name]
54
- name = (name =~ / /) ? (name.split(' ').map.with_index { |x, i| x = x.bold if i == 0; x }.join ' ') : name.bold
55
-
56
- puts "#{' ' * (5 - args[:num].to_s.length)}" + args[:num].to_s + ' | Page: ' + name
57
- puts "#{' ' * 5}" + ' | Description: ' + args[:description].to_s
58
- self.separator
66
+ name = if name =~ / /
67
+ name.split.map.with_index do |x, i|
68
+ x = x.bold if i.zero?
69
+ x
70
+ end.join " "
71
+ else
72
+ name.bold
73
+ end
74
+
75
+ puts "#{" " * (5 - args[:num].to_s.length)}#{args[:num]} | Page: #{name}"
76
+ puts "#{" " * 5} | Description: #{args[:description]}"
77
+ separator
59
78
  end
60
79
  end
61
80
 
62
-
81
+ #
82
+ # Table view for search operation.
83
+ #
63
84
  class Table < Common
64
-
65
85
  def self.header(args)
66
86
  @@first_col = args[:first_col]
67
- n_length = ( args[:first_col] - 4 ) / 2
87
+ nl = (args[:first_col] - 4) / 2
68
88
 
69
- puts (' ' * 4) + '#' +
70
- ' | ' + (' ' * n_length) + 'Page' + (' ' * n_length) +
71
- ' | Description '
72
- self.separator
89
+ puts "#{" " * 4}# | #{" " * nl} Page#{" " * nl} | Description"
90
+ separator
73
91
  end
74
92
 
75
93
  def self.package(args)
76
94
  name = args[:name]
77
- name = (name =~ / /) ? (name.split(' ').map.with_index { |x, i| x = x.bold if i == 0; x }.join ' ') : name.bold
78
-
79
- puts (' ' * (5 - args[:num].to_s.length)) + args[:num].to_s +
80
- ' | ' + name + (' ' * (@@first_col - args[:name].length)) +
81
- ' | ' + args[:description]
82
- self.separator
95
+ name = if name =~ / /
96
+ name.split.map.with_index do |x, i|
97
+ x = x.bold if i.zero?
98
+ x
99
+ end.join " "
100
+ else
101
+ name.bold
102
+ end
103
+
104
+ nl = 5 - args[:num].to_s.length
105
+ fl = @@first_col - args[:name].length
106
+ puts "#{" " * nl}#{args[:num]} | #{name}#{" " * fl} | #{args[:description]}"
107
+ separator
83
108
  end
84
-
85
109
  end
86
110
 
87
111
  class Urls < Table
88
-
89
112
  end
90
-
91
113
  end
92
114
 
93
-
94
115
  module Page
95
-
116
+ #
117
+ # Common view elements for page operation.
118
+ #
96
119
  class Common
97
-
98
120
  def self.separator
99
- puts '-' * SEPARATOR_LENGTH
121
+ puts "-" * SEPARATOR_LENGTH
100
122
  end
101
123
 
102
124
  def self.general(args)
103
- puts ''
104
- puts '=' * SEPARATOR_LENGTH
105
- puts 'Parameters: '.bold +
106
- 'Engine: ' + args[:engine].bold.red + ' | ' +
107
- 'OS: ' + args[:distro].bold.blue + ' | ' +
108
- 'Architecture: ' + PageData::FORMATS[args[:architecture]].bold + ' | ' +
109
- 'Cache: ' + (args[:refresh] ? 'Off'.bold : "#{'On'.bold.yellow} (#{args[:cache_time] ? args[:cache_time].strftime('%Y-%m-%d %H:%M') : args[:cache_time].strftime('%Y-%m-%d %H:%M')})")
110
- puts '=' * SEPARATOR_LENGTH
111
- puts 'Name: '.bold + args[:name]
112
- puts 'Summary: '.bold + args[:short_description] if args[:short_description]
113
- puts 'Description: '.bold + args[:description].chomp if args[:description]
114
-
125
+ engine = args[:engine].bold.red
126
+ distro = args[:distro].bold.blue
127
+ arch = PageData::FORMATS[args[:architecture]].bold
128
+ cache = if args[:refresh]
129
+ "Off".bold
130
+ elsif args[:cache_time]
131
+ "#{"On".bold.yellow} (#{args[:cache_time].strftime("%Y-%m-%d %H:%M")})"
132
+ else
133
+ "#{"On".bold.yellow} (Now)"
134
+ end
135
+
136
+ puts ""
137
+ puts "=" * SEPARATOR_LENGTH
138
+ puts "#{"Parameters: ".bold} Engine: #{engine} | OS: #{distro} | Architecture: #{arch} | Cache: #{cache}"
139
+ puts "=" * SEPARATOR_LENGTH
140
+ puts "#{"Name: ".bold}#{args[:name]}"
141
+ puts "#{"Summary: ".bold}#{args[:short_description]}" if args[:short_description]
142
+ puts "#{"Description: ".bold}#{args[:description].chomp}" if args[:description]
115
143
  end
116
144
 
117
145
  def self.no_packages(compatible)
118
- self.separator
119
- puts (' ' * 3) + ' - | No ' + (compatible ? 'compatible ' : '' ) + 'packages found!'
120
- self.separator
146
+ separator
147
+ puts "#{" " * 3} - | No #{compatible ? "compatible" : ""} packages found!"
148
+ separator
121
149
  end
122
150
 
123
151
  def self.no_item(num)
124
- self.separator
125
- puts (' ' * 3) + ' - | Invalid item number ' + num.to_s
152
+ separator
153
+ puts "#{" " * 3} - | Invalid item number #{num}"
126
154
  end
127
155
  end
128
156
 
129
-
157
+ #
158
+ # Table view for page operation.
159
+ #
130
160
  class Table < Common
131
-
132
161
  def self.header(args)
133
162
  @@first_col = args[:first_col]
134
163
  @@second_col = args[:second_col]
135
- first_col = ((args[:first_col] - 4) / 2)
136
- second_col = (args[:second_col] > 0) ? ((args[:second_col] - 6) / 2) : 0
137
164
 
138
- self.separator
139
- if second_col > 0
140
- puts "#{' ' * 3} # | Version | #{' ' * first_col}Repo #{' ' * first_col} | #{' ' * second_col} Distro #{' ' * second_col}" # | Formats"
165
+ first_col = (args[:first_col] - 4) / 2
166
+ second_col = args[:second_col].positive? ? ((args[:second_col] - 6) / 2) : 0
167
+ np = " " * 3
168
+ fcp = " " * first_col
169
+ scp = " " * second_col
170
+
171
+ separator
172
+ if second_col.positive?
173
+ puts "#{np} # | Version | #{fcp}Repo #{fcp} | #{scp} Distro #{scp}"
141
174
  else
142
- puts "#{' ' * 3} # | Version | #{' ' * first_col}Repo #{' ' * first_col}" # | Formats"
175
+ puts "#{np} # | Version | #{fcp}Repo"
143
176
  end
144
- self.separator
177
+ separator
145
178
  end
146
179
 
147
180
  def self.package(args)
148
- r_length = @@first_col - args[:pack][:repo].to_s.length
149
- n_length = args[:num].to_s.length
150
- d_length = @@second_col > 0 ? @@second_col - args[:pack][:distro].to_s.length : 0
151
-
152
181
  num = args[:num].to_s.bold.send(TYPE_COLORS[args[:pack][:type]])
153
182
  repo = args[:pack][:repo].bold.send(TYPE_COLORS[args[:pack][:type]])
154
- distro = (args[:args][:distro] == args[:pack][:distro] ? args[:pack][:distro].bold.blue : args[:pack][:distro])
183
+ distro = if args[:args][:distro] == args[:pack][:distro]
184
+ args[:pack][:distro].bold.blue
185
+ else
186
+ args[:pack][:distro]
187
+ end
155
188
  version = args[:pack][:version].to_s[0..6]
156
189
 
157
- if @@second_col > 0
158
- puts (' ' * (5 - n_length)) + num +
159
- ' | ' + (' ' * ( 7 - version.length )) + version +
160
- ' | ' + repo.to_s + (' ' * r_length) +
161
- ' | ' + distro + (' ' * d_length) # +
190
+ nl = 5 - args[:num].to_s.length
191
+ rl = @@first_col - args[:pack][:repo].to_s.length
192
+ dl = @@second_col.positive? ? @@second_col - args[:pack][:distro].to_s.length : 0
193
+ vl = 7 - version.length
194
+
195
+ if @@second_col.positive?
196
+ puts "#{" " * nl}#{num} | #{" " * vl}#{version} | #{repo}#{" " * rl} | #{distro}#{" " * dl}"
162
197
  else
163
- puts (' ' * (5 - n_length)) + num +
164
- ' | ' + (' ' * ( 7 - version.length )) + version +
165
- ' | ' + repo.to_s + (' ' * r_length) #+
198
+ puts "#{" " * nl}#{num} | #{" " * vl}#{version} | #{repo}"
166
199
  end
167
-
168
- self.separator
200
+ separator
169
201
  end
170
-
171
202
  end
172
203
 
173
-
204
+ #
205
+ # Report view for page operation.
206
+ #
174
207
  class Report < Common
175
-
176
208
  def self.header(args)
177
209
  @@second_col = args[:second_col]
178
- self.separator
179
- puts "#{' ' * 3} # | Info"
180
- self.separator
210
+ separator
211
+ puts "#{" " * 3} # | Info"
212
+ separator
181
213
  end
182
214
 
183
215
  def self.package(args)
184
216
  n_length = args[:num].to_s.length
185
-
186
- #p args
187
217
  num = args[:num].to_s.bold.send(TYPE_COLORS[args[:pack][:type]])
188
218
  repo = args[:pack][:repo].bold.send(TYPE_COLORS[args[:pack][:type]])
189
- distro = (args[:args][:distro] == args[:pack][:distro] ? args[:pack][:distro].bold.blue : args[:pack][:distro])
219
+ distro = if args[:args][:distro] == args[:pack][:distro]
220
+ args[:pack][:distro].bold.blue
221
+ else
222
+ args[:pack][:distro]
223
+ end
190
224
  version = args[:pack][:version].to_s
191
-
192
- puts (' ' * (5 - n_length)) + num.to_s + ' | Version: ' + version
193
- puts (' ' * 5) + ' | Repository: ' + repo
194
- puts (' ' * 5) + ' | Distribution: ' + distro if @@second_col > 0
195
- #puts (' ' * 5) + ' | Formats: ' + args[:formats].join(', ')
196
- puts (' ' * 5) + ' | Type: ' + args[:pack][:type].to_s.capitalize.bold.send(TYPE_COLORS[args[:pack][:type]])
197
- self.separator
225
+ type = args[:pack][:type].to_s.capitalize.bold.send(TYPE_COLORS[args[:pack][:type]])
226
+ prefix = " " * 5
227
+
228
+ puts "#{" " * (5 - n_length)}#{num} | Version: #{version}"
229
+ puts "#{prefix} | Repository: #{repo}"
230
+ puts "#{prefix} | Distribution: #{distro}" if @@second_col.positive?
231
+ # puts #{prefix} | Formats: ' + args[:formats].join(', ')
232
+ puts "#{prefix} | Type: #{type}"
233
+ separator
198
234
  end
199
-
200
235
  end
201
236
 
202
-
203
237
  class Urls < Table
204
-
205
238
  end
206
-
207
- end # Module Page
208
-
239
+ end
209
240
 
210
241
  module Links
211
-
242
+ #
243
+ # Common class for links view.
244
+ #
212
245
  class Common < Page::Common
213
-
214
246
  def self.info_package(args)
215
- self.separator
216
- puts 'Selected Item: '.bold +
217
- 'Repository: ' + args[:repo].bold.send(TYPE_COLORS[args[:type]]) + ' | ' +
218
- 'Distribution: ' + args[:distro].bold + ' | ' +
219
- 'Version: ' + args[:version].bold
220
- self.separator
247
+ separator
248
+ repo = args[:repo].bold.send(TYPE_COLORS[args[:type]])
249
+ distro = args[:distro].bold
250
+ ver = args[:version].bold
251
+ puts "#{"Selected Item:".bold} Repository: #{repo} | Distribution: #{distro} | Version: #{ver}"
252
+ separator
221
253
  end
222
254
 
223
255
  def self.header(args)
@@ -225,72 +257,73 @@ module Zypper
225
257
  end
226
258
  end
227
259
 
260
+ #
261
+ # Table view for links operation.
262
+ #
228
263
  class Table < Common
229
-
230
264
  def self.header(args)
231
265
  super args
232
- self.separator
233
- puts (' ' * 3) + ' # | Format | Link'
234
- self.separator
266
+ separator
267
+ puts "#{" " * 3} # | Format | Link"
268
+ separator
235
269
  end
236
270
 
237
- def self.package(args)
238
- end
271
+ def self.package(args); end
239
272
 
240
273
  def self.link(args)
241
- #puts args,@@first_col
242
- n_length = args[:num].to_s.length
243
- puts (' ' * (5 - n_length)) + args[:num].to_s + ' | ' +
244
- (' ' * (6 - args[:pack][:format].to_s.length)) + args[:pack][:format].to_s + ' | ' + args[:pack][:link]
245
- self.separator
274
+ nl = args[:num].to_s.length
275
+ fl = args[:pack][:format].to_s.length
276
+ puts "#{" " * (5 - nl)}#{args[:num]} | #{" " * (6 - fl)}#{args[:pack][:format]} | #{args[:pack][:link]}"
277
+ separator
246
278
  end
247
279
  end
248
280
 
281
+ #
282
+ # Report view for links operation.
283
+ #
249
284
  class Report < Common
250
-
251
- def self.header(args)
252
- self.separator
253
- puts "#{' ' * 3} # | Links"
254
- self.separator
285
+ def self.header(_args)
286
+ separator
287
+ puts "#{" " * 3} # | Links"
288
+ separator
255
289
  end
256
290
 
257
291
  def self.link(args)
258
- alt_format = args[:pack][:format].to_s == PageData::FORMATS[args[:pack][:format]] ? '' : " (#{PageData::FORMATS[args[:pack][:format]]})"
292
+ alt_format = if args[:pack][:format].to_s == PageData::FORMATS[args[:pack][:format]]
293
+ ""
294
+ else
295
+ " (#{PageData::FORMATS[args[:pack][:format]]})"
296
+ end
259
297
  n_length = args[:num].to_s.length
260
- puts (' ' * (5 - n_length)) + args[:num].to_s + ' | Format: ' + args[:pack][:format].to_s.bold + alt_format
261
- puts (' ' * 5) + ' | Distribution: ' + args[:pack][:distro]
262
- puts (' ' * 5) + ' | Link: ' + args[:pack][:link]
298
+ puts "#{" " * (5 - n_length)}#{args[:num]} | Format: #{args[:pack][:format].to_s.bold}#{alt_format}"
299
+ puts "#{" " * 5} | Distribution: #{args[:pack][:distro]}"
300
+ puts "#{" " * 5} | Link: #{args[:pack][:link]}"
263
301
 
264
- self.separator
302
+ separator
265
303
  end
266
304
  end
267
305
 
306
+ #
307
+ # URLs view for links operation.
308
+ #
268
309
  class Urls
269
- def self.general(args)
270
- end
310
+ def self.general(args); end
271
311
 
272
- def self.info_package(args)
273
- end
312
+ def self.info_package(args); end
274
313
 
275
- def self.header(args)
276
- end
314
+ def self.header(args); end
277
315
 
278
- def self.separator
279
- end
316
+ def self.separator; end
280
317
 
281
- def self.package(args)
282
- end
318
+ def self.package(args); end
283
319
 
284
320
  def self.link(args)
285
321
  puts args[:pack][:link]
286
322
  end
287
323
 
288
- def self.no_packages(args)
289
- end
324
+ def self.no_packages(args); end
290
325
  end
291
-
292
- end # Module Links
293
-
326
+ end
294
327
  end
295
328
  end
296
329
  end