class OpenvasCli::VasPeriod
Attributes
number[R]
period[R]
Public Class Methods
from_months(months)
click to toggle source
# 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)
click to toggle source
# 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
new(params={})
click to toggle source
# 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
Public Instance Methods
+(rhs)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/openvas-cli/vas_period.rb, line 32 def <=> (rhs) to_seconds - rhs.to_seconds end
number=(v)
click to toggle source
# File lib/openvas-cli/vas_period.rb, line 22 def number=(v) number_will_change! unless @number == v @number = v end
period=(v)
click to toggle source
# File lib/openvas-cli/vas_period.rb, line 27 def period=(v) period_will_change! unless @period == v @period = v end
to_seconds()
click to toggle source
# 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