Class: WeWorkRemotely::Company

Inherits:
Object
  • Object
show all
Defined in:
lib/weworkremotely/company.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#jobsObject

Returns the value of attribute jobs.



2
3
4
# File 'lib/weworkremotely/company.rb', line 2

def jobs
  @jobs
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/weworkremotely/company.rb', line 2

def name
  @name
end

Class Method Details

.allObject



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_allObject



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

#categoriesObject



34
35
36
# File 'lib/weworkremotely/company.rb', line 34

def categories
  self.jobs.collect { |job| job.category }.uniq
end

#saveObject



19
20
21
# File 'lib/weworkremotely/company.rb', line 19

def save
  @@all << self
end