Class: Population

Inherits:
Object
  • Object
show all
Includes:
DataFactory, DateFactory, Foundry, StringFactory, Workflows
Defined in:
lib/sambal-kuali/data_objects/population.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Workflows

#go_to_academic_calendar, #go_to_calendar_search, #go_to_create_course_offerings, #go_to_create_population, #go_to_display_schedule_of_classes, #go_to_holiday_calendar, #go_to_manage_course_offerings, #go_to_manage_population, #go_to_perform_rollover, #go_to_rollover_details, #log_in, #logged_in_user

Constructor Details

#initialize(browser, opts = {}) ⇒ Population

Returns a new instance of Population.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sambal-kuali/data_objects/population.rb', line 12

def initialize(browser, opts={})
  @browser = browser

  defaults = {
    :name=>random_alphanums.strip,
    :description=>random_alphanums_plus.strip, # TODO: figure out why random_multiline does not validate properly
    :type=>"rule-based",
    :child_populations=>[],
    :rule=>nil,
    :reference_population=>nil,
    :status=>"Active"
  }
  options = defaults.merge(opts)

  set_options(options)
  operations = {:"union-based"=>"union",:"intersection-based"=>"intersection",:"exclusion-based"=>"exclusion"}
  @operation = operations[type.to_sym]
end

Instance Attribute Details

#child_populationsObject

Returns the value of attribute child_populations.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def child_populations
  @child_populations
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def description
  @description
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def name
  @name
end

#operationObject

Returns the value of attribute operation.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def operation
  @operation
end

#reference_populationObject

Returns the value of attribute reference_population.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def reference_population
  @reference_population
end

#ruleObject

Returns the value of attribute rule.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def rule
  @rule
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def status
  @status
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/sambal-kuali/data_objects/population.rb', line 9

def type
  @type
end

Instance Method Details

#add_child_population(child_population) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/sambal-kuali/data_objects/population.rb', line 134

def add_child_population(child_population)
  on CreatePopulation do |page|
    page.lookup_population
  end
  on ActivePopulationLookup do |page|
    page.keyword.wait_until_present
    page.keyword.set child_population
    page.search
    page.return_value child_population
  end
  on CreatePopulation do |page|
    page.wait_until(30) { page.child_population.value == child_population }
    page.add
  end
end

#add_random_populationObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/sambal-kuali/data_objects/population.rb', line 150

def add_random_population
  on CreatePopulation do |page|
    page.lookup_population
  end
  population = search_for_random_pop
  on ActivePopulationLookup do |page|
    page.return_value population
  end
  on CreatePopulation do |page|
    page.wait_until(30) { page.child_population.value == population }
    page.add
  end
  population
end

#add_random_ref_popObject



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/sambal-kuali/data_objects/population.rb', line 180

def add_random_ref_pop
  on CreatePopulation do |page|
    page.lookup_ref_population
  end
  population = search_for_random_pop
  on ActivePopulationLookup do |page|
    page.return_value population
  end
  on CreatePopulation do |page|
    page.wait_until(30) { page.reference_population.value == population }
  end
  population
end

#add_ref_pop(population) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/sambal-kuali/data_objects/population.rb', line 165

def add_ref_pop(population)
  on CreatePopulation do |page|
    page.lookup_ref_population
  end
  on ActivePopulationLookup do |page|
    page.keyword.wait_until_present
    page.keyword.set population
    page.search
    page.return_value population
  end
  on CreatePopulation do |page|
    page.wait_until(30) { page.reference_population.value == population }
  end
end

#createObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sambal-kuali/data_objects/population.rb', line 31

def create
  go_to_create_population
  on CreatePopulation do |page|
    page.name.set @name
    page.description.set @description
    page.by_using_populations unless @type == 'rule-based'
    case(@type)
      when 'rule-based'
        # Select a random rule if none is defined
        @rule=random_rule(page) if @rule == nil
        page.rule.select @rule
      when 'union-based'
        # Select union...
        page.union
      when 'intersection-based'
        # Select intersection...
        page.intersection
      when 'exclusion-based'
        # Select exclusion...
        page.exclusion
        @reference_population == nil ? @reference_population = add_random_ref_pop : add_ref_pop(@reference_population) unless @reference_population == " "
      else
        raise "Your population type value must be one of the following:\n'rule-based', 'union-based', 'intersection-based', or 'exclusion-based'.\nPlease update your script"
     end
    unless type=='rule-based'
      if @child_populations.length == 0
        2.times { @child_populations << add_random_population }
      else
        @child_populations.each do |pop|
          if pop == "random"
            pop.replace(add_random_population)
          else
            add_child_population(pop)
          end
        end
      end
    end
  end
  on CreatePopulation do |page|
    # Click the create population button...
    page.create
  end
  sleep 10
end

#edit_population(opts = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/sambal-kuali/data_objects/population.rb', line 76

def edit_population opts={}

  defaults = {
    :name=>@name,
    :description=>@description,
    :status=>@status,
    :rule=>@rule,
    :reference_population=>@reference_population,
    :child_populations=>@child_populations
  }
  options=defaults.merge(opts)

  go_to_manage_population
  on ManagePopulations do |page|
    page.keyword.set @name
    page.both.set
    page.search
    page.edit @name
  end
  on EditPopulation do |page|
    page.name.set options[:name]
    page.description.set options[:description]
    page.send(options[:status].downcase).set
    if options[:rule] == "random"
      options[:rule]=new_random_rule(page)
    end
    page.rule.select(options[:rule]) unless options[:rule] == nil

    if options[:reference_population] == "random"
      options[:reference_population] = update_random_ref_pop
      @reference_population = options[:reference_population] #updating instance variable immediately - don't want to reuse this pop
    else
      update_ref_pop(options[:reference_population]) unless options[:reference_population] == @reference_population or options[:reference_population]  == nil
    end

    unless @child_populations == options[:child_populations] or options[:child_populations] == []
      page.child_populations.reverse.each { |pop| page.remove_population(pop) }
      @child_populations = options[:child_populations] #updating instance variable immediately - don't want to reuse this pop
      @child_populations.each do |pop|
        if pop == "random"
          pop.replace(add_random_population)
        else
          add_child_population(pop)
        end
      end
      options[:child_populations] = @child_populations #keep in sync
    end

    page.update

    if page.first_msg == "Document was successfully submitted."
      set_options(options)
    else
      # Do not update the Population attributes.
    end
  end
end

#new_random_rule(page) ⇒ Object



231
232
233
234
235
236
237
238
# File 'lib/sambal-kuali/data_objects/population.rb', line 231

def new_random_rule(page)
  new_rule = random_rule(page)
  if new_rule == @rule
    new_random_rule(page)
  else
    new_rule
  end
end

#random_rule(page) ⇒ Object

Returns (as a string) one of the rules listed in the Rule selection list.



223
224
225
226
227
228
229
# File 'lib/sambal-kuali/data_objects/population.rb', line 223

def random_rule(page)
  rules = []
  page.rule.options.to_a.each { |item| rules << item.text }
  rules.delete(@rule) unless @rule == nil
  rules.shuffle!
  rules[0]
end

#update_random_ref_popObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/sambal-kuali/data_objects/population.rb', line 207

def update_random_ref_pop
  pop = ""
  on EditPopulation do |page|
    page.lookup_ref_population
  end
  pop = search_for_random_pop
  on ActivePopulationLookup do |page|
    page.return_value pop
  end
  on CreatePopulation do |page|
    page.wait_until(30) { page.reference_population.value == pop }
  end
  pop
end

#update_ref_pop(pop) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/sambal-kuali/data_objects/population.rb', line 194

def update_ref_pop(pop)
  on EditPopulation do |page|
    page.lookup_ref_population
  end
  pop = search_for_random_pop
  on ActivePopulationLookup do |page|
    page.return_value pop
  end
  on CreatePopulation do |page|
    page.wait_until(30) { page.reference_population.value == pop }
  end
end