Class: Berta::Entities::Expiration
- Inherits:
-
Object
- Object
- Berta::Entities::Expiration
- Defined in:
- lib/berta/entities/expiration.rb
Overview
Class for storing expiration data, also can be created from xml
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
-
.check_xml!(xml) ⇒ Object
Raises error if XML element is not in correct format.
-
.from_xml(xml) ⇒ Berta::Entities::Expiration
Creates Expiration class instance from XMLElement.
Instance Method Summary collapse
-
#==(other) ⇒ Object
TODO: doc.
-
#default_action? ⇒ Boolean
Determines if this expiration has default expiration action set.
-
#in_expiration_interval? ⇒ Boolean
Determines if this schelude action is in expiration interval.
-
#in_notification_interval? ⇒ Boolean
Determines if this schelude action is in notification interval.
-
#initialize(id, time, action) ⇒ Expiration
constructor
Creates expiration class instance from given arguments.
-
#template ⇒ String
Generate schelude action template that can be used in VMS USER_TEMPLATE/SCHED_ACTION.
Constructor Details
#initialize(id, time, action) ⇒ Expiration
Creates expiration class instance from given arguments.
33 34 35 36 37 |
# File 'lib/berta/entities/expiration.rb', line 33 def initialize(id, time, action) @id = id @time = time @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/berta/entities/expiration.rb', line 5 def action @action end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/berta/entities/expiration.rb', line 5 def id @id end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
5 6 7 |
# File 'lib/berta/entities/expiration.rb', line 5 def time @time end |
Class Method Details
.check_xml!(xml) ⇒ Object
Raises error if XML element is not in correct format.
21 22 23 24 25 26 |
# File 'lib/berta/entities/expiration.rb', line 21 def self.check_xml!(xml) raise Berta::Errors::Entities::InvalidEntityXMLError, 'wrong enxpiration xml recieved' \ unless %w[ID ACTION TIME].all? { |path| xml.has_elements? path } end |
.from_xml(xml) ⇒ Berta::Entities::Expiration
Creates Expiration class instance from XMLElement.
12 13 14 15 |
# File 'lib/berta/entities/expiration.rb', line 12 def self.from_xml(xml) check_xml!(xml) Berta::Entities::Expiration.new(xml['ID'], xml['TIME'], xml['ACTION']) end |
Instance Method Details
#==(other) ⇒ Object
TODO: doc
82 83 84 |
# File 'lib/berta/entities/expiration.rb', line 82 def ==(other) id == other.id && action == other.action && time == other.time end |
#default_action? ⇒ Boolean
Determines if this expiration has default expiration action set. Default expiration action is action defined in settings file.
77 78 79 |
# File 'lib/berta/entities/expiration.rb', line 77 def default_action? action == Berta::Settings.expiration.action end |
#in_expiration_interval? ⇒ Boolean
Determines if this schelude action is in expiration interval. That means its expiration is closer to Time.now that expiration offset.
68 69 70 71 |
# File 'lib/berta/entities/expiration.rb', line 68 def in_expiration_interval? time_interval = time.to_i - Time.now.to_i time_interval <= Berta::Settings.expiration_offset && time_interval >= 0 end |
#in_notification_interval? ⇒ Boolean
Determines if this schelude action is in notification interval. That means its expiration is closer to Time.now than notification deadline.
58 59 60 61 |
# File 'lib/berta/entities/expiration.rb', line 58 def in_notification_interval? time_interval = time.to_i - Time.now.to_i time_interval <= Berta::Settings.notification_deadline && time_interval >= 0 end |
#template ⇒ String
Generate schelude action template that can be used in VMS USER_TEMPLATE/SCHED_ACTION
43 44 45 46 47 48 49 50 51 |
# File 'lib/berta/entities/expiration.rb', line 43 def template <<-VM_TEMPLATE SCHED_ACTION = [ ID = "#{id}", ACTION = "#{action}", TIME = "#{time}" ] VM_TEMPLATE end |