Class: WeWorkRemotely::Job

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, company: nil, name: nil, description: nil, published_date: nil, url: nil, category: nil) ⇒ Job

Returns a new instance of Job.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/weworkremotely/job.rb', line 6

def initialize(id: nil, company: nil, name: nil, description: nil, published_date: nil, url: nil, category: nil)
  @id = id if id
  @name = name
  @published_date = published_date if published_date
  @url = url if url
  @description = description if description
  @company = WeWorkRemotely::Company.find_or_create_by_name(company) if company
  @company.add_job(self)
  @category = WeWorkRemotely::Category.find_or_create_by_name(category) if category
  @category.add_job(self)
  @@all << self
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#companyObject

Returns the value of attribute company.



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

def company
  @company
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#published_dateObject

Returns the value of attribute published_date.



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

def published_date
  @published_date
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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

def self.all
  @@all
end

.destroy_allObject



27
28
29
# File 'lib/weworkremotely/job.rb', line 27

def self.destroy_all
  @@all.clear
end

.find_by_id(id) ⇒ Object



23
24
25
# File 'lib/weworkremotely/job.rb', line 23

def self.find_by_id(id)
  self.all.detect { |job| job.id == id }
end