scrapin-a-livin 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/generic/listing.rb +120 -18
  3. data/test/listing_test.rb +113 -0
  4. metadata +4 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -3,23 +3,125 @@
3
3
  # A generic job listing
4
4
  class JobListing
5
5
 
6
- attr_reader :title
7
- attr_reader :link
8
- attr_reader :company
9
- attr_reader :company_link
10
- attr_reader :location
11
- attr_reader :date
12
- attr_reader :repost
13
-
14
- # Initializer for the job listing
15
- def initialize(title, link, company, company_link, location, date)
16
-
17
- @title = title
18
- @link = link
19
- @company = company
20
- @company_link = company_link
21
- @location = location
22
- @date = date
23
- end
6
+ attr_reader :title
7
+ attr_reader :link
8
+ attr_reader :company
9
+ attr_reader :company_link
10
+ attr_reader :location
11
+ attr_reader :date
12
+ attr_reader :repost
13
+
14
+ def initialize(title, link, company, company_link, location, date)
15
+
16
+ @title = title
17
+ @link = link
18
+ @company = company
19
+ @company_link = company_link
20
+ @location = location
21
+ @date = date
22
+ end
23
+
24
+ # The state where the job is listed
25
+ def state
26
+ location.split(",")[1].strip
27
+ end
28
+
29
+ # The city where the job is listed
30
+ def city
31
+ location.split(",")[0].strip
32
+ end
33
+
34
+ # Convert to string
35
+ def to_s
36
+ "Title: #@title\n" +
37
+ "Link: #@link\n" +
38
+ "Company: #@company\n" +
39
+ "Company Link: #@company_link\n" +
40
+ "Location: #@location\n" +
41
+ "Date: #@date\n"
42
+ end
43
+
44
+ # Add the state for the listing to the path
45
+ #
46
+ # @param basepath [String, #read] the base directory path
47
+ # @param listing [JobListing, #read] the job listing
48
+ # @return [String] the new path with the state appended
49
+ def add_state(basepath)
50
+
51
+ state_path = "#{basepath}/" + replace_invalid(state).upcase
52
+
53
+ # Create the directories
54
+ Dir.mkdir(state_path) if !File.exists?(state_path)
55
+
56
+ return state_path
57
+ end
58
+
59
+ # Add the city for the listing to the path
60
+ #
61
+ # @param basepath [String, #read] the base directory path
62
+ # @param listing [JobListing, #read] the job listing
63
+ # @return [String] the new path with the city appended
64
+ def add_city(basepath)
65
+
66
+ city_path = "#{basepath}/" + replace_invalid(city).capitalize
67
+
68
+ # Create the directories
69
+ Dir.mkdir(city_path) if !File.exists?(city_path)
70
+
71
+ return city_path
72
+ end
73
+
74
+ # Add the date for the listing to the path
75
+ #
76
+ # @param basepath [String, #read] the base directory path
77
+ # @param listing [JobListing, #read] the job listing
78
+ # @return [String] the new path with the date appended
79
+ def add_date(basepath)
80
+
81
+ date_path = "#{basepath}/" + date.tr(" ", "_").tr(",", "")
82
+
83
+ # Create the directories
84
+ Dir.mkdir(date_path) if !File.exists?(date_path)
85
+
86
+ return date_path
87
+ end
88
+
89
+ # Add the company for the listing to the path
90
+ #
91
+ # @param basepath [String, #read] the base directory path
92
+ # @param listing [JobListing, #read] the job listing
93
+ # @return [String] the new path with the company appended
94
+ def add_company(basepath)
95
+
96
+ # Get the directory
97
+ company_path = "#{basepath}/" + replace_invalid(company)
98
+
99
+ # Check to see if the date folder is available
100
+ Dir.mkdir(company_path) if !File.exists?(company_path)
101
+
102
+ return company_path
103
+ end
104
+
105
+ # Add the name for the listing to the path
106
+ #
107
+ # @param basepath [String, #read] the base directory path
108
+ # @param listing [JobListing, #read] the job listing
109
+ # @return [String] the new path with the company appended
110
+ def add_name(basepath)
111
+
112
+ name_path = "#{basepath}/" + replace_invalid(title)
113
+ end
114
+
115
+ private
116
+ # Replace the invalid characters in the provided string
117
+ #
118
+ # @param name [String, #read] the string to check
119
+ # @return [String] the name with the invalid characters replaced
120
+ def replace_invalid(name)
121
+ name.sub("&", "&")\
122
+ .sub("'", "-")\
123
+ .tr(" ", "_")\
124
+ .tr("!@\#$%^*()'~`;:'\"<>,./?", "-")
125
+ end
24
126
 
25
127
  end
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test_helper'
3
+ require 'shoulda'
4
+ require 'fileutils'
5
+
6
+ # Test Case for the Job Listing Class
7
+ #
8
+ class TC_JobListing < Test::Unit::TestCase
9
+
10
+ TMP_DIR = './tmp'
11
+
12
+ context "Check default parameters: " do
13
+
14
+ setup do
15
+
16
+ # Create the job listing
17
+ @listing = JobListing.new(
18
+ "Software Developer",
19
+ "http://www.google.com",
20
+ "Google Inc.",
21
+ "http://careers.google.com",
22
+ "Mountain View, CA",
23
+ "Dec, 1")
24
+ end
25
+
26
+ should "have same name" do
27
+ assert_equal("Software Developer", @listing.title)
28
+ end
29
+
30
+ should "have same link" do
31
+ assert_equal("http://www.google.com", @listing.link)
32
+ end
33
+
34
+ should "have same company name" do
35
+ assert_equal("Google Inc.", @listing.company)
36
+ end
37
+
38
+ should "have same company link" do
39
+ assert_equal("http://careers.google.com", @listing.company_link)
40
+ end
41
+
42
+ should "have same date" do
43
+ assert_equal("Dec, 1", @listing.date)
44
+ end
45
+
46
+ should "have parsed city" do
47
+ assert_equal("Mountain View", @listing.city)
48
+ end
49
+
50
+ should "have parsed state" do
51
+ assert_equal("CA", @listing.state)
52
+ end
53
+
54
+ should "print the information" do
55
+
56
+ text = "Title: Software Developer\n" +
57
+ "Link: http://www.google.com\n" +
58
+ "Company: Google Inc.\n" +
59
+ "Company Link: http://careers.google.com\n" +
60
+ "Location: Mountain View, CA\n" +
61
+ "Date: Dec, 1\n"
62
+
63
+ assert_equal(text, @listing.to_s)
64
+ end
65
+
66
+ end
67
+
68
+ context "Check path replacements" do
69
+
70
+ setup do
71
+
72
+ # Create the job listing
73
+ @listing = JobListing.new(
74
+ "Begin !@\#$%^&*()'~`;:'\"<>,./?&amp;&#039; End",
75
+ "http://www.google.com",
76
+ "Begin !@\#$%^&*()'~`;:'\"<>,./?&amp;&#039; End",
77
+ "http://careers.google.com",
78
+ "Begin !@\#$%^&*()'~`;:'\"<>./?&amp;&#039; End, CA",
79
+ "Dec, 1")
80
+
81
+ # Create the temp directory
82
+ Dir.mkdir TMP_DIR
83
+ end
84
+
85
+ teardown do
86
+ # Delete the temp directory
87
+ FileUtils.rm_r TMP_DIR
88
+ end
89
+
90
+ should "replace invalid name characters" do
91
+ path = "./tmp/Begin_------&----------------&-_End"
92
+ assert_equal(path, @listing.add_name(TMP_DIR))
93
+ end
94
+
95
+ should "replace invalid date characters" do
96
+ path = "./tmp/Dec_1"
97
+ assert_equal(path, @listing.add_date(TMP_DIR))
98
+ assert(true, File.exists?(path))
99
+ end
100
+
101
+ should "replace invalid company characters" do
102
+ path = "./tmp/Begin_------&----------------&-_End"
103
+ assert_equal(path, @listing.add_company(TMP_DIR))
104
+ assert(true, File.exists?(path))
105
+ end
106
+
107
+ should "replace invalid city characters" do
108
+ path = "./tmp/Begin_------&---------------&-_end"
109
+ assert_equal(path, @listing.add_city(TMP_DIR))
110
+ assert(true, File.exists?(path))
111
+ end
112
+ end
113
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrapin-a-livin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin S Kirkup
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-28 00:00:00 -05:00
12
+ date: 2009-11-30 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,7 @@ files:
65
65
  - lib/scrapin-a-livin.rb
66
66
  - lib/yahoo/hotjobs.rb
67
67
  - test/dice_parser_test.rb
68
+ - test/listing_test.rb
68
69
  - test/queries/dice/queryAustin.html
69
70
  - test/queries/dice/queryRaleigh.html
70
71
  - test/queries/dice/querySanJose.html
@@ -108,4 +109,5 @@ test_files:
108
109
  - test/scripts/hotjobsDump.rb
109
110
  - test/yahoo_parser_test.rb
110
111
  - test/dice_parser_test.rb
112
+ - test/listing_test.rb
111
113
  - test/test_helper.rb