Class: OpenvasCli::VasPeriod
- Inherits:
-
Object
- Object
- OpenvasCli::VasPeriod
- Includes:
- ActiveModel::Dirty, ActiveModel::Validations, Comparable
- Defined in:
- lib/openvas-cli/vas_period.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
-
#period ⇒ Object
Returns the value of attribute period.
Class Method Summary collapse
Instance Method Summary collapse
- #+(rhs) ⇒ Object
- #-(rhs) ⇒ Object
- #<=>(rhs) ⇒ Object
-
#initialize(params = {}) ⇒ VasPeriod
constructor
A new instance of VasPeriod.
- #to_seconds ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ VasPeriod
Returns a new instance of VasPeriod.
17 18 19 20 |
# File 'lib/openvas-cli/vas_period.rb', line 17 def initialize(params={}) @number = params[:number] if params[:number] @period = params[:period] if params[:period] end |
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
9 10 11 |
# File 'lib/openvas-cli/vas_period.rb', line 9 def number @number end |
#period ⇒ Object
Returns the value of attribute period.
10 11 12 |
# File 'lib/openvas-cli/vas_period.rb', line 10 def period @period end |
Class Method Details
.from_months(months) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/openvas-cli/vas_period.rb', line 81 def self.from_months(months) if months % 12 == 0 VasPeriod.new(:number => months / 12, :period => :month) else VasPeriod.new(:number => months, :period => :month) end end |
.from_seconds(seconds) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/openvas-cli/vas_period.rb', line 69 def self.from_seconds(seconds) if seconds % 86400 == 0 VasPeriod.new(:number => seconds / 86400, :period => :day) elsif seconds % 3600 == 0 VasPeriod.new(:number => seconds / 3600, :period => :hour) elsif seconds % 60 == 0 VasPeriod.new(:number => seconds / 60, :period => :minute) else VasPeriod.new(:number => seconds, :period => :second) end end |
Instance Method Details
#+(rhs) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/openvas-cli/vas_period.rb', line 36 def + (rhs) if rhs.kind_of? VasPeriod VasPeriod.from_seconds(to_seconds + rhs.to_seconds) else VasPeriod.from_seconds(to_seconds + rhs) end end |
#-(rhs) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/openvas-cli/vas_period.rb', line 44 def - (rhs) if rhs.kind_of? VasPeriod VasPeriod.from_seconds(to_seconds - rhs.to_seconds) else VasPeriod.from_seconds(to_seconds - rhs) end end |
#<=>(rhs) ⇒ Object
32 33 34 |
# File 'lib/openvas-cli/vas_period.rb', line 32 def <=> (rhs) to_seconds - rhs.to_seconds end |
#to_seconds ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/openvas-cli/vas_period.rb', line 52 def to_seconds case @period when :year @number * 365.25 * 86400 when :month @number * 365.25 * 86400 / 12 when :day @number * 86400 when :hour @number * 3600 when :minute @number * 60 else @number end end |