1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 02:33:19 +00:00

minor clean code

This commit is contained in:
nishiki 2016-07-10 19:04:34 +02:00
parent 13b025df2b
commit f68882181d

View file

@ -21,8 +21,6 @@ require 'i18n'
module MPW
class Item
attr_accessor :error_msg
attr_accessor :id
attr_accessor :name
attr_accessor :group
@ -41,8 +39,7 @@ class Item
# raise an error if the hash hasn't the key name
def initialize(options={})
if not options.has_key?(:name) or options[:name].to_s.empty?
@error_msg = I18n.t('error.update.name_empty')
raise @error_msg
raise I18n.t('error.update.name_empty')
end
if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty?
@ -60,11 +57,9 @@ class Item
# Update the item
# @args: options -> a hash of parameter
# @rtrn: true if the item is update
def update(options={})
if options.has_key?(:name) and options[:name].to_s.empty?
@error_msg = I18n.t('error.update.name_empty')
return false
raise I18n.t('error.update.name_empty')
end
@name = options[:name] if options.has_key?(:name)
@ -75,8 +70,6 @@ class Item
@port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty?
@comment = options[:comment] if options.has_key?(:comment)
@last_edit = Time.now.to_i if not options.has_key?(:no_update_last_edit)
return true
end
# Update last_sync
@ -85,7 +78,6 @@ class Item
end
# Delete all data
# @rtrn: true
def delete
@id = nil
@name = nil
@ -98,8 +90,6 @@ class Item
@created = nil
@last_edit = nil
@last_sync = nil
return true
end
def empty?