Class: JobListing

Inherits:
Object
  • Object
show all
Defined in:
lib/generic/listing.rb

Overview

A generic job listing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, link, company, company_link, location, date, repost) ⇒ JobListing

Returns a new instance of JobListing.



12
13
14
15
16
17
18
19
20
21
# File 'lib/generic/listing.rb', line 12

def initialize(title, link, company, company_link, location, date, repost)

     @title = title
     @link = link
     @company = company
     @company_link = company_link
     @location = location
     @date = date
     @repost = repost
end

Instance Attribute Details

#companyObject (readonly)

Returns the value of attribute company.



8
9
10
# File 'lib/generic/listing.rb', line 8

def company
  @company
end

Returns the value of attribute company_link.



9
10
11
# File 'lib/generic/listing.rb', line 9

def company_link
  @company_link
end

Returns the value of attribute link.



7
8
9
# File 'lib/generic/listing.rb', line 7

def link
  @link
end

#locationObject (readonly)

Returns the value of attribute location.



10
11
12
# File 'lib/generic/listing.rb', line 10

def location
  @location
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/generic/listing.rb', line 6

def title
  @title
end

Instance Method Details

#add_city(basepath) ⇒ String

Add the city for the listing to the path

Parameters:

  • basepath (String, #read)

    the base directory path

  • listing (JobListing, #read)

    the job listing

Returns:

  • (String)

    the new path with the city appended



76
77
78
79
80
81
82
83
84
# File 'lib/generic/listing.rb', line 76

def add_city(basepath)

     city_path = "#{basepath}/" + replace_invalid(city).capitalize

     # Create the directories
     Dir.mkdir(city_path) if !File.exists?(city_path)

     return city_path
end

#add_company(basepath) ⇒ String

Add the company for the listing to the path

Parameters:

  • basepath (String, #read)

    the base directory path

  • listing (JobListing, #read)

    the job listing

Returns:

  • (String)

    the new path with the company appended



106
107
108
109
110
111
112
113
114
115
# File 'lib/generic/listing.rb', line 106

def add_company(basepath)

     # Get the directory
     company_path = "#{basepath}/" + replace_invalid(@company)

     # Check to see if the date folder is available
     Dir.mkdir(company_path) if !File.exists?(company_path)

     return company_path
end

#add_date(basepath) ⇒ String

Add the date for the listing to the path

Parameters:

  • basepath (String, #read)

    the base directory path

  • listing (JobListing, #read)

    the job listing

Returns:

  • (String)

    the new path with the date appended



91
92
93
94
95
96
97
98
99
# File 'lib/generic/listing.rb', line 91

def add_date(basepath)

     date_path = "#{basepath}/" + date.tr(" -", "_").tr(",", "")

     # Create the directories
     Dir.mkdir(date_path) if !File.exists?(date_path)

     return date_path
end

#add_name(basepath) ⇒ String

Add the name for the listing to the path

Parameters:

  • basepath (String, #read)

    the base directory path

  • listing (JobListing, #read)

    the job listing

Returns:

  • (String)

    the new path with the company appended



122
123
124
125
# File 'lib/generic/listing.rb', line 122

def add_name(basepath)

     name_path = "#{basepath}/" + replace_invalid(@title)
end

#add_state(basepath) ⇒ String

Add the state for the listing to the path

Parameters:

  • basepath (String, #read)

    the base directory path

  • listing (JobListing, #read)

    the job listing

Returns:

  • (String)

    the new path with the state appended



61
62
63
64
65
66
67
68
69
# File 'lib/generic/listing.rb', line 61

def add_state(basepath)

     state_path = "#{basepath}/" + replace_invalid(state).upcase

     # Create the directories
     Dir.mkdir(state_path) if !File.exists?(state_path)

     return state_path
end

#cityObject

The city where the job is listed



41
42
43
# File 'lib/generic/listing.rb', line 41

def city
  location.split(",")[0].strip
end

#dateObject

Retrieve the date of the job listing



24
25
26
27
28
29
30
31
32
33
# File 'lib/generic/listing.rb', line 24

def date

     # Return the reposted date if it has been specified
     if @repost != nil
          @repost
     else
          @date
     end

end

#stateObject

The state where the job is listed



36
37
38
# File 'lib/generic/listing.rb', line 36

def state
  location.split(",")[1].strip
end

#to_sObject

Convert to string



46
47
48
49
50
51
52
53
54
# File 'lib/generic/listing.rb', line 46

def to_s
  "Title: #@title\n" +
  "Link: #@link\n" +
  "Company: #@company\n" +
  "Company Link: #@company_link\n" +
  "Location: #@location\n" +
  "Date: #@date\n" +
  "Repost: #@repost\n"
end