Module: AnswerFactory

Defined in:
lib/answers/batch.rb,
lib/answers/answer.rb,
lib/machines/any_one.rb,
lib/factories/factory.rb,
lib/factories/workstation.rb,
lib/machines/build_random.rb,
lib/machines/infrastructure.rb,
lib/machines/point_crossover.rb,
lib/machines/mutate_codeblock.rb,
lib/machines/mutate_footnotes.rb,
lib/machines/select_nondominated.rb,
lib/machines/evaluate_simple_score.rb,
lib/machines/select_by_summed_rank.rb,
lib/machines/evaluate_with_test_cases.rb

Defined Under Namespace

Modules: Machines Classes: Answer, Batch, Factory, Workstation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gem_rootObject



30
31
32
# File 'lib/answer-factory.rb', line 30

def AnswerFactory.gem_root
  File.dirname(__FILE__) + '/..'
end

Instance Method Details

#add_tag(new_tag) ⇒ Object

Raises:

  • (ArgumentError)


124
125
126
127
# File 'lib/answers/answer.rb', line 124

def add_tag(new_tag)
  raise ArgumentError, "#{new_tag} is not a Symbol" unless new_tag.kind_of?(Symbol)
  @tags.add(new_tag)
end

#dataObject



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/answers/answer.rb', line 135

def data
  basics = Hash.new
  basics["_id"] = self.couch_id unless self.couch_id.empty? 
  basics["_rev"] = self.couch_rev unless self.couch_rev.empty? 
  
  basics.merge!({'blueprint' => self.blueprint,
    'location' => self.location.to_sym,
    'tags' => self.tags.to_a, 
    'scores' => self.scores,
    'progress' => self.progress,
    'timestamp' => self.timestamp.to_f})
  return basics
end

#from_serial_hash(hash) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/answers/answer.rb', line 150

def from_serial_hash(hash)
  value_hash = hash["value"]
  tag_set = Set.new(value_hash["tags"].collect {|t| t.to_sym})
  symbolized_scores = value_hash["scores"].inject({}) {|memo,(k,v)| memo[k.to_sym] = v; memo }
      
  Answer.new(value_hash["blueprint"],
    couch_id:value_hash['_id'],
    couch_rev:value_hash['_rev'],
    location:(value_hash["location"] || "NOWHERE").to_sym,
    tags:tag_set,
    scores:symbolized_scores,
    progress:value_hash["progress"],
    timestamp:Time.at(value_hash["timestamp"].to_f))
end

#move_to(where) ⇒ Object

Raises:

  • (ArgumentError)


117
118
119
120
121
# File 'lib/answers/answer.rb', line 117

def move_to(where)
  raise ArgumentError, "#{where} is not a Symbol" unless where.kind_of?(Symbol)
  @location = where.to_sym
  self
end

#remove_tag(old_tag) ⇒ Object



130
131
132
# File 'lib/answers/answer.rb', line 130

def remove_tag(old_tag)
  @tags.delete(old_tag)
end