Class: AnswerFactory::Workstation
- Inherits:
-
Object
- Object
- AnswerFactory::Workstation
- Defined in:
- lib/factories/workstation.rb
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#downstream_stations ⇒ Object
Returns the value of attribute downstream_stations.
-
#factory_name ⇒ Object
readonly
Returns the value of attribute factory_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #after_cycle! ⇒ Object
- #build! ⇒ Object
- #couchdb_create_view(db_uri = couchdb_uri) ⇒ Object
- #couchdb_uri ⇒ Object
- #couchdb_viewdoc ⇒ Object
- #cycle ⇒ Object
- #gather_mine ⇒ Object
-
#initialize(name, options = {}) ⇒ Workstation
constructor
A new instance of Workstation.
- #process_with(operator) ⇒ Object
- #receive! ⇒ Object
- #scrap! ⇒ Object
- #scrap_everything ⇒ Object
- #scrap_if(why, &filter) ⇒ Object
- #ship! ⇒ Object
- #ship_to(where) ⇒ Object
- #transfer_answer(which, where) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Workstation
Returns a new instance of Workstation.
9 10 11 12 13 14 15 16 |
# File 'lib/factories/workstation.rb', line 9 def initialize(name, = {}) raise ArgumentError, "#{name} is not a Symbol" unless name.kind_of?(Symbol) @name = name @factory_name = configatron.factory.name @capacity = [:capacity] || 100 @downstream_stations = Array.new @answers = Batch.new end |
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
6 7 8 |
# File 'lib/factories/workstation.rb', line 6 def answers @answers end |
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
4 5 6 |
# File 'lib/factories/workstation.rb', line 4 def capacity @capacity end |
#downstream_stations ⇒ Object
Returns the value of attribute downstream_stations.
5 6 7 |
# File 'lib/factories/workstation.rb', line 5 def downstream_stations @downstream_stations end |
#factory_name ⇒ Object (readonly)
Returns the value of attribute factory_name.
4 5 6 |
# File 'lib/factories/workstation.rb', line 4 def factory_name @factory_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/factories/workstation.rb', line 4 def name @name end |
Instance Method Details
#after_cycle! ⇒ Object
107 108 109 110 |
# File 'lib/factories/workstation.rb', line 107 def after_cycle! @answers.bulk_save!(couchdb_uri) @answers = Batch.new end |
#build! ⇒ Object
42 43 44 45 |
# File 'lib/factories/workstation.rb', line 42 def build! # Workstation is a superclass; the default behavior (doing nothing) # should be overridden in a subclass definition end |
#couchdb_create_view(db_uri = couchdb_uri) ⇒ Object
66 67 68 |
# File 'lib/factories/workstation.rb', line 66 def couchdb_create_view(db_uri = couchdb_uri) CouchRest.database!(db_uri).save_doc(self.couchdb_viewdoc, use_uuids=false) end |
#couchdb_uri ⇒ Object
25 26 27 |
# File 'lib/factories/workstation.rb', line 25 def couchdb_uri "#{configatron.factory.couchdb.server}/#{configatron.factory.couchdb.name}" end |
#couchdb_viewdoc ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/factories/workstation.rb', line 55 def couchdb_viewdoc {'_id' => "_design/#{@name.to_s}", views: { current: { map: "function(doc) { if(doc.location == '#{@name.to_s}') { emit(doc._id, doc); } }" } } } end |
#cycle ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/factories/workstation.rb', line 112 def cycle self.receive! self.build! self.ship! self.scrap! self.after_cycle! end |
#gather_mine ⇒ Object
36 37 38 39 |
# File 'lib/factories/workstation.rb', line 36 def gather_mine gathered = Batch.load_from_couch(couchdb_uri, "#{name}/current") @answers = gathered end |
#process_with(operator) ⇒ Object
48 49 50 51 52 |
# File 'lib/factories/workstation.rb', line 48 def process_with(operator) raise ArgumentError, "Workstation#process_with cannot process with a #{operator.class}" unless operator.kind_of?(Machines::Machine) operator.generate(@answers) end |
#receive! ⇒ Object
30 31 32 33 |
# File 'lib/factories/workstation.rb', line 30 def receive! # Workstation is a superclass; the default behavior (doing nothing) # should be overridden in a subclass definition end |
#scrap! ⇒ Object
91 92 93 94 |
# File 'lib/factories/workstation.rb', line 91 def scrap! # Workstation is a superclass; the default behavior (doing nothing) # should be overridden in a subclass definition end |
#scrap_everything ⇒ Object
102 103 104 |
# File 'lib/factories/workstation.rb', line 102 def scrap_everything ship_to(:SCRAP) end |
#scrap_if(why, &filter) ⇒ Object
97 98 99 100 |
# File 'lib/factories/workstation.rb', line 97 def scrap_if(why, &filter) ship_to(:SCRAP, &filter) # (@answers.find_all &filter).each {|a| a.add_tag :SCRAP; a.remove_tag @name} end |
#ship! ⇒ Object
71 72 73 74 |
# File 'lib/factories/workstation.rb', line 71 def ship! # Workstation is a superclass; the default behavior (doing nothing) # should be overridden in a subclass definition end |
#ship_to(where) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/factories/workstation.rb', line 77 def ship_to(where) raise ArgumentError, "Workstation#ship_to cannot ship to a #{where.class}" unless where.kind_of?(Symbol) @answers.each do |a| next unless a.location.to_sym == @name.to_sym if block_given? next unless yield(a) end a.move_to(where) end end |
#transfer_answer(which, where) ⇒ Object
19 20 21 22 23 |
# File 'lib/factories/workstation.rb', line 19 def transfer_answer(which, where) raise ArgumentError, "#{where} is not a Symbol" unless where.kind_of?(Symbol) which.remove_tag(self.name) which.add_tag(where) end |