Class: WeWorkRemotely::Company
- Inherits:
-
Object
- Object
- WeWorkRemotely::Company
- Defined in:
- lib/weworkremotely/company.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#jobs ⇒ Object
Returns the value of attribute jobs.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .all ⇒ Object
- .create(name) ⇒ Object
- .destroy_all ⇒ Object
- .find_or_create_by_name(name, *job) ⇒ Object
Instance Method Summary collapse
- #add_job(job) ⇒ Object
- #categories ⇒ Object
-
#initialize(name) ⇒ Company
constructor
A new instance of Company.
- #save ⇒ Object
Constructor Details
#initialize(name) ⇒ Company
Returns a new instance of Company.
6 7 8 9 |
# File 'lib/weworkremotely/company.rb', line 6 def initialize(name) @name = name @jobs = [] end |
Instance Attribute Details
#jobs ⇒ Object
Returns the value of attribute jobs.
2 3 4 |
# File 'lib/weworkremotely/company.rb', line 2 def jobs @jobs end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/weworkremotely/company.rb', line 2 def name @name end |
Class Method Details
.all ⇒ Object
11 12 13 |
# File 'lib/weworkremotely/company.rb', line 11 def self.all @@all end |
.create(name) ⇒ Object
23 24 25 26 27 |
# File 'lib/weworkremotely/company.rb', line 23 def self.create(name) company = WeWorkRemotely::Company.new(name) company.save company end |
.destroy_all ⇒ Object
15 16 17 |
# File 'lib/weworkremotely/company.rb', line 15 def self.destroy_all @@all.clear end |
.find_or_create_by_name(name, *job) ⇒ Object
38 39 40 |
# File 'lib/weworkremotely/company.rb', line 38 def self.find_or_create_by_name(name, *job) self.all.detect { |company| company.name == name } || self.create(name) end |
Instance Method Details
#add_job(job) ⇒ Object
29 30 31 32 |
# File 'lib/weworkremotely/company.rb', line 29 def add_job(job) self.jobs << job unless self.jobs.include?(job) job.company = self unless job.company == self end |
#categories ⇒ Object
34 35 36 |
# File 'lib/weworkremotely/company.rb', line 34 def categories self.jobs.collect { |job| job.category }.uniq end |
#save ⇒ Object
19 20 21 |
# File 'lib/weworkremotely/company.rb', line 19 def save @@all << self end |