Class: FrequencyConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/macrohub.rb

Instance Method Summary collapse

Constructor Details

#initialize(freqx, freq: freqx) ⇒ FrequencyConstraint



108
109
110
111
112
113
# File 'lib/macrohub.rb', line 108

def initialize(freqx, freq: freqx)
  
  @freq = freq
  @counter = 0
  @interval = 60
end

Instance Method Details

#counterObject



115
116
117
# File 'lib/macrohub.rb', line 115

def counter()
  @counter
end

#incrementObject



119
120
121
# File 'lib/macrohub.rb', line 119

def increment()
  @counter += 1
end

#match?Boolean



123
124
125
# File 'lib/macrohub.rb', line 123

def match?()
  @counter < @freq
end

#resetObject



127
128
129
130
# File 'lib/macrohub.rb', line 127

def reset()
  puts 'resetting' if $debug
  @counter = 0
end

#to_nodeObject



132
133
134
135
# File 'lib/macrohub.rb', line 132

def to_node()
  Rexle::Element.new(:constraint, \
                      attributes: {type: :frequency, freq: @freq})      
end

#to_rowxObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/macrohub.rb', line 137

def to_rowx()
  
  freq = case @freq
  when 1
    'Once'
  when 2
    'Twice'
  else
    "Maximum %s times" % @freq
  end
  
  "constraint: %s" %  freq

end