Class: GCI::Job::Collection
- Inherits:
-
Object
- Object
- GCI::Job::Collection
- Defined in:
- lib/gci/job.rb
Instance Method Summary collapse
- #<<(job) ⇒ Object
- #[](name) ⇒ Object
- #build(**attrs, &block) ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Collection
Returns a new instance of Collection.
6 7 8 |
# File 'lib/gci/job.rb', line 6 def initialize @data = [] end |
Instance Method Details
#<<(job) ⇒ Object
16 17 18 19 20 |
# File 'lib/gci/job.rb', line 16 def <<(job) @data << job self end |
#[](name) ⇒ Object
29 30 31 |
# File 'lib/gci/job.rb', line 29 def [](name) @data.detect { |job| job.name == name } end |
#build(**attrs, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/gci/job.rb', line 10 def build(**attrs, &block) job = Job.new(**attrs, &block) @data << job job end |
#to_h ⇒ Object
22 23 24 25 26 27 |
# File 'lib/gci/job.rb', line 22 def to_h @data.each_with_object({}) do |job, acc| acc.merge!(job.name => job.attributes) acc end end |