app/models/offerings/offering.rb
# Returns a new or existing Population with the requested starting set. The starting set can be any valid association
# or method of this Offering that returns an array of objects. If the population doesn't exist, it is created and the
# +system+ boolean flag is set.
# 
# Since Populations must have a unique title, this method will automatically increment the title for a newly-created
# Population if needed. So if a population with the name already exists, this method will create a population with a
# "2" at the end of the title. If something with a "2" already exists, the new title will have a "3", and so on, until
# a valid title is found.
Returns a new or existing Population with the requested starting set. The starting set can be any valid association
or method of this Offering that returns an array of objects. If the population doesn't exist, it is created and the
+system+ boolean flag is set.

Since Populations must have a unique title, this method will automatically increment the title for a newly-created
Population if needed. So if a population with the name already exists, this method will create a population with a
"2" at the end of the title. If something with a "2" already exists, the new title will have a "3", and so on, until
a valid title is found.
Returns a new or existing Population with the requested starting set . The starting set can be any valid association or method of this Offering that returns an array of objects . If the population doesn ' t exist it is created and the + system + boolean flag is set . Since Populations must have a unique title this method will automatically increment the title for a newly - created Population if needed . So if a population with the name already exists this method will create a population with a " 2 " at the end of the title . If something with a " 2 " already exists the new title will have a " 3 " and so on until a valid title is found .
def population(starting_set)
    starting_set = starting_set.to_s if starting_set.is_a?(Symbol)
    p = Population.find_or_initialize_by_populatable_type_and_populatable_id_and_starting_set_and_conditions_counter(
          "Offering", self.id, starting_set, 0)
    if p.new_record?
      p.title = "#{self.title}: #{starting_set.titleize}"
      until p.valid? && !p.errors.on(:title)
        if p.title[/\d+$/].nil?
          p.title += " 2"
        else
          new_num = p.title[/\d+$/].to_i + 1
          p.title.gsub!(/\d+$/, new_num.to_s)
        end
      end 
      p.system = true
      p.description = "Automatically generated by Offering ##{self.id} from starting set '#{starting_set}'"
      p.access_level = "everyone"
      p.save
    end
    p
  end
def population ( starting_set ) starting_set = starting_set . to_s if starting_set . is_a? ( Symbol ) p = Population . find_or_initialize_by_populatable_type_and_populatable_id_and_starting_set_and_conditions_counter ( "Offering" , self . id , starting_set , 0 ) if p . new_record? p . title = "#{self.title}: #{starting_set.titleize}" until p . valid? && ! p . errors . on ( :title ) if p . title [ / \d +$ / ] . nil? p . title += " 2" else new_num = p . title [ / \d +$ / ] . to_i + 1 p . title . gsub! ( / \d +$ / , new_num . to_s ) end end p . system = true p . description = "Automatically generated by Offering ##{self.id} from starting set '#{starting_set}'" p . access_level = "everyone" p . save end p end
Returns a new or existing Population with the requested starting set.
Returns a new or existing Population with the requested starting set .
starting_set