1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-03-19 12:59:30 +00:00

feat: replace host by url in table

This commit is contained in:
Adrien Waksberg 2017-05-06 09:09:17 +02:00
parent a7a165bca9
commit f91531b856
2 changed files with 32 additions and 12 deletions

View file

@ -179,18 +179,21 @@ module MPW
data = { id: { length: 3, color: 'cyan' },
host: { length: 9, color: 'yellow' },
user: { length: 7, color: 'green' },
protocol: { length: 9, color: 'white' },
port: { length: 5, color: 'white' },
otp: { length: 4, color: 'white' },
comment: { length: 14, color: 'magenta' } }
items.each do |item|
data.each do |k, v|
next if k == :id || k == :otp
case k
when :id, :otp
next
when :host
v[:length] = item.url.length + 3 if item.url.length >= v[:length]
else
v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length]
end
end
end
data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length]
data.each_value { |v| length_total += v[:length] }
@ -231,17 +234,23 @@ module MPW
data.each do |k, v|
next if k == :id
if k == :otp
print '| '
case k
when :otp
item.otp ? (print ' X ') : 4.times { print ' ' }
next
end
when :host
print "#{item.protocol}://" if item.protocol
print item.host.send(v[:color])
print ":#{item.port}" if item.port
(v[:length] - item.url.to_s.length).times { print ' ' }
print '| '
else
print item.send(k.to_s).to_s.send(v[:color])
(v[:length] - item.send(k.to_s).to_s.length).times { print ' ' }
end
end
print "\n"
i += 1

View file

@ -81,6 +81,17 @@ module MPW
@last_edit = nil
end
# Return data on url format
# @return [String] an url
def url
url = ''
url += "#{@protocol}://" if @protocol
url += @host
url += ":#{@port}" if @port
url
end
def empty?
@id.to_s.empty?
end