Class: MPW::Item
- Inherits:
-
Object
- Object
- MPW::Item
- Defined in:
- lib/mpw/item.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#created ⇒ Object
Returns the value of attribute created.
-
#group ⇒ Object
Returns the value of attribute group.
-
#host ⇒ Object
Returns the value of attribute host.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_edit ⇒ Object
Returns the value of attribute last_edit.
-
#otp ⇒ Object
Returns the value of attribute otp.
-
#port ⇒ Object
Returns the value of attribute port.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete all data.
- #empty? ⇒ Boolean
-
#initialize(**options) ⇒ Item
constructor
A new instance of Item.
- #nil? ⇒ Boolean
-
#update(**options) ⇒ Object
Update the item.
-
#url ⇒ String
Return data on url format.
Constructor Details
#initialize(**options) ⇒ Item
Returns a new instance of Item.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mpw/item.rb', line 35 def initialize(**) if !.key?(:host) || [:host].to_s.empty? raise I18n.t('error.update.host_empty') end if !.key?(:id) || [:id].to_s.empty? || !.key?(:created) || [:created].to_s.empty? @id = generate_id @created = Time.now.to_i else @id = [:id] @created = [:created] @last_edit = [:last_edit] [:no_update_last_edit] = true end update() end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
30 31 32 |
# File 'lib/mpw/item.rb', line 30 def comment @comment end |
#created ⇒ Object
Returns the value of attribute created.
32 33 34 |
# File 'lib/mpw/item.rb', line 32 def created @created end |
#group ⇒ Object
Returns the value of attribute group.
24 25 26 |
# File 'lib/mpw/item.rb', line 24 def group @group end |
#host ⇒ Object
Returns the value of attribute host.
25 26 27 |
# File 'lib/mpw/item.rb', line 25 def host @host end |
#id ⇒ Object
Returns the value of attribute id.
23 24 25 |
# File 'lib/mpw/item.rb', line 23 def id @id end |
#last_edit ⇒ Object
Returns the value of attribute last_edit.
31 32 33 |
# File 'lib/mpw/item.rb', line 31 def last_edit @last_edit end |
#otp ⇒ Object
Returns the value of attribute otp.
29 30 31 |
# File 'lib/mpw/item.rb', line 29 def otp @otp end |
#port ⇒ Object
Returns the value of attribute port.
28 29 30 |
# File 'lib/mpw/item.rb', line 28 def port @port end |
#protocol ⇒ Object
Returns the value of attribute protocol.
26 27 28 |
# File 'lib/mpw/item.rb', line 26 def protocol @protocol end |
#user ⇒ Object
Returns the value of attribute user.
27 28 29 |
# File 'lib/mpw/item.rb', line 27 def user @user end |
Instance Method Details
#delete ⇒ Object
Delete all data
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mpw/item.rb', line 71 def delete @id = nil @group = nil @host = nil @protocol = nil @user = nil @port = nil @otp = nil @comment = nil @created = nil @last_edit = nil end |
#empty? ⇒ Boolean
95 96 97 |
# File 'lib/mpw/item.rb', line 95 def empty? @id.to_s.empty? end |
#nil? ⇒ Boolean
99 100 101 |
# File 'lib/mpw/item.rb', line 99 def nil? false end |
#update(**options) ⇒ Object
Update the item
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mpw/item.rb', line 55 def update(**) if .key?(:host) && [:host].to_s.empty? raise I18n.t('error.update.host_empty') end @group = [:group] if .key?(:group) @host = [:host] if .key?(:host) @protocol = [:protocol] if .key?(:protocol) @user = [:user] if .key?(:user) @port = [:port].to_i if .key?(:port) && ![:port].to_s.empty? @otp = [:otp] if .key?(:otp) @comment = [:comment] if .key?(:comment) @last_edit = Time.now.to_i unless .key?(:no_update_last_edit) end |
#url ⇒ String
Return data on url format
86 87 88 89 90 91 92 93 |
# File 'lib/mpw/item.rb', line 86 def url url = '' url += "#{@protocol}://" if @protocol url += @host url += ":#{@port}" if @port url end |