Class: IceT::Rule::Base
- Inherits:
-
Object
- Object
- IceT::Rule::Base
- Extended by:
- Comparable
- Includes:
- Comparable
- Defined in:
- lib/ice_t/rule/base.rb
Instance Attribute Summary collapse
-
#at ⇒ Object
Returns the value of attribute at.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(interval = 1, at_str = nil) ⇒ Base
constructor
A new instance of Base.
- #occurrences(start_time, end_time) ⇒ Object
Constructor Details
#initialize(interval = 1, at_str = nil) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 22 23 |
# File 'lib/ice_t/rule/base.rb', line 15 def initialize(interval = 1, at_str = nil) raise ArgumentError.new('Positive integer required') if interval.nil? || interval.to_i < 1 || interval % 1 != 0 @interval = interval @at = at_str @export_class_name = self.class.name self.at = at_str unless @at.nil? end |
Instance Attribute Details
#at ⇒ Object
Returns the value of attribute at.
13 14 15 |
# File 'lib/ice_t/rule/base.rb', line 13 def at @at end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
12 13 14 |
# File 'lib/ice_t/rule/base.rb', line 12 def interval @interval end |
Class Method Details
.<=>(other) ⇒ Object
7 8 9 |
# File 'lib/ice_t/rule/base.rb', line 7 def <=>(other) self.to_i <=> other.to_i end |
Instance Method Details
#<=>(other) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ice_t/rule/base.rb', line 34 def <=>(other) case when self.class == other.class && self.interval == other.interval 0 when self.class == other.class && self.interval < other.interval -1 when self.class == other.class && self.interval > other.interval +1 when self.class.to_i < other.class.to_i -1 when self.class.to_i > other.class.to_i +1 else nil end end |
#occurrences(start_time, end_time) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/ice_t/rule/base.rb', line 54 def occurrences(start_time, end_time) diff = IceT::TimeHelper.diff_by_unit(start_time, end_time, self.class.unit) (1..diff).step(self.interval).map { |i| start_time.advance(self.class.unit => i) } end |