chamba_search_mx 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 314046f5b3c5a33b5eb7690cbd7c35e253b96819
4
+ data.tar.gz: 314bd2a0905007d1ee93c5496985d9325630ccfd
5
+ SHA512:
6
+ metadata.gz: f3bb0cec85ca5d9e2acf6d49acf0e294816ea5ec105e2d092eb874bc2dc746776c1e43fe52ac756ac0ea1413ae7b2ca3f497c3fc66549777ef6beed7dda69481
7
+ data.tar.gz: ae7b800437747bc51959b47acdbc3420cc1518d0d319e3a170f3b8a45a9e80936792d612666d3c2e42e57e093a5b95c6cfd6291032757fd6906726600407ea47
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format NyanCatFormatter
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ FrozenStringLiteralComment:
2
+ Enabled: false
3
+ AllCops:
4
+ Exclude:
5
+ - 'chamba_search_mx.gemspec'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/.vimrc ADDED
@@ -0,0 +1 @@
1
+ set makeprg=rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [v0.1.0]
8
+ ### Added
9
+ - ChambaSearchMx module added by @richistron
10
+ - ChambaSearchMx.find 'query', location: '', days: '', salary: '' by @richistron
11
+ - rspec tests added by @richistron
12
+
13
+ [v0.1.0]:https://github.com/richistron/chamba_search_mx/tree/v0.1.0
14
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chamba_search_mx.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ricardo Rivas G.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Chamba Search MX
2
+
3
+ This gem allows you to find jobs in México.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chamba_search_mx'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chamba_search_mx
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'chamba_search_mx'
25
+
26
+ jobs = ChambaSearchMx.find 'ruby developer'
27
+
28
+ jobs.each do |job|
29
+ puts job.url
30
+ puts job.title
31
+ puts job.email
32
+ end
33
+ ```
34
+
35
+ ## Options
36
+
37
+ Locations
38
+
39
+ ```
40
+ ags, bcn, bcs, cam, chi, chp, coa, col, default, df, dgo, gro, gto, hgo,
41
+ jal, mch, mex, mor, mx, nay, nl, oax, pue, qr, qro, sina, slp, sono, tab,
42
+ tam, tlx, us, ver, world, yuc, zac
43
+ ```
44
+
45
+ Salaries
46
+ ```
47
+ 0-5000, 5000-10000, 10000-15000, 15000-20000, 20000-30000, 30000-40000,
48
+ 40000-50000, 50000-65000, 65000-80000, 80000
49
+ ```
50
+
51
+ Days
52
+ ```
53
+ 1, 2, 3, 4, 5, 6, 7, 14, 30, 60
54
+ ```
55
+
56
+ Example
57
+ ```ruby
58
+ options = {
59
+ location: 'mx',
60
+ days: 2,
61
+ salary: '15000-20000'
62
+ }
63
+ ChambaSearchMx.find 'ruby developer', options
64
+ ```
65
+
66
+ ## Development
67
+
68
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
69
+
70
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/richistron/chamba_search_mx.
75
+
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
80
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'chamba_search_mx'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chamba_search_mx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'chamba_search_mx'
8
+ spec.version = ChambaSearchMx::VERSION
9
+ spec.authors = ['Ricardo Rivas G.']
10
+ spec.email = ['richistron@gmail.com']
11
+
12
+ spec.summary = 'This gem allows you to search jobs from the internets'
13
+ spec.description = 'Job Finder for Mexico'
14
+ # spec.homepage = 'TODO: Put your gem's website or public repo URL here.'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set
18
+ # the 'allowed_push_host' to allow pushing to a single host or delete this
19
+ # section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = 'TODO: Set to http://mygemserver.com'
22
+ # else
23
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ # 'public gem pushes.'
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.13'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rspec-mocks', '~> 3.5'
38
+ spec.add_development_dependency 'byebug', '~> 9.0'
39
+ spec.add_development_dependency 'rubocop', '~> 0.4'
40
+ spec.add_development_dependency 'nyan-cat-formatter', '~> 0.11'
41
+ spec.add_dependency 'nokogiri', '~> 1.6'
42
+ end
@@ -0,0 +1,29 @@
1
+ require 'chamba_search_mx/factories/base_url'
2
+ require 'chamba_search_mx/factories/days'
3
+ require 'chamba_search_mx/factories/locations'
4
+ require 'chamba_search_mx/factories/salaries'
5
+ require 'chamba_search_mx/finder'
6
+ require 'chamba_search_mx/html_page'
7
+ require 'chamba_search_mx/job_decorator'
8
+ require 'chamba_search_mx/job_page'
9
+ require 'chamba_search_mx/pagination'
10
+ require 'chamba_search_mx/search_page'
11
+ require 'chamba_search_mx/url_formatter'
12
+
13
+ ##
14
+ # ChambaSearchMx module allows you to search jobs and get back a ruby object
15
+ # with useful information about the position openenings published on the web
16
+ module ChambaSearchMx
17
+ ##
18
+ # Public api of this module. This method takes case of parsing the opts
19
+ # argument into a internal api, this acts basically as a connector
20
+ def self.find(opts = {})
21
+ finder = opts[:finder] || ChambaSearchMx::Finder.new
22
+ search_options = {
23
+ location: opts[:location],
24
+ salary: opts[:salary],
25
+ days: opts[:days]
26
+ }
27
+ finder.find(opts[:search], search_options).jobs
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # this is a secret!
4
+ BASE_URL = 'https://www.occ.com.mx'.freeze
5
+ end
@@ -0,0 +1,16 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # days options
4
+ DAYS = {
5
+ '1': 'ayer',
6
+ '2': 'desde-hace-2-dias',
7
+ '3': 'desde-hace-3-dias',
8
+ '4': 'desde-hace-4-dias',
9
+ '5': 'desde-hace-5-dias',
10
+ '6': 'desde-hace-6-dias',
11
+ '7': 'desde-hace-7-dias',
12
+ '14': 'desde-hace-14-dias',
13
+ '30': 'desde-hace-30-dias',
14
+ '60': 'desde-hace-60-dias'
15
+ }.freeze
16
+ end
@@ -0,0 +1,42 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # available locations
4
+ LOCATIONS = {
5
+ ags: 'empleos-en-aguascalientes',
6
+ bcn: 'empleos-en-baja-california',
7
+ bcs: 'empleos-en-baja-california-sur',
8
+ cam: 'empleos-en-campeche',
9
+ chi: 'empleos-en-chihuahua',
10
+ chp: 'empleos-en-chiapas',
11
+ coa: 'empleos-en-coahuila',
12
+ col: 'empleos-en-colima',
13
+ default: 'empleos-en-mexico-y-el-mundo',
14
+ df: 'empleos-en-df-y-zona-metro',
15
+ dgo: 'empleos-en-durango',
16
+ gro: 'empleos-en-guerrero',
17
+ gto: 'empleos-en-guanajuato',
18
+ hgo: 'empleos-en-hidalgo',
19
+ jal: 'empleos-en-jalisco',
20
+ mch: 'empleos-en-michoacan',
21
+ mex: 'empleos-en-edo-mexico',
22
+ mor: 'empleos-en-morelos',
23
+ mx: 'empleos-en-empleos-en-mexico',
24
+ nay: 'empleos-en-nayarit',
25
+ nl: 'empleos-en-nuevo león',
26
+ oax: 'empleos-en-oaxaca',
27
+ pue: 'empleos-en-puebla',
28
+ qr: 'empleos-en-quintana roo',
29
+ qro: 'empleos-en-queretaro',
30
+ sina: 'empleos-en-sinaloa',
31
+ slp: 'empleos-en-san luis potose',
32
+ sono: 'empleos-en-sonora',
33
+ tab: 'empleos-en-tabasco',
34
+ tam: 'empleos-en-tamaulipas',
35
+ tlx: 'empleos-en-tlaxcala',
36
+ us: 'empleos-en-estados unidos',
37
+ ver: 'empleos-en-veracruz',
38
+ world: 'empleos-en-resto del mundo',
39
+ yuc: 'empleos-en-yucatán',
40
+ zac: 'empleos-en-zacatecas'
41
+ }.freeze
42
+ end
@@ -0,0 +1,16 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # available salary ranges
4
+ SALARIES = {
5
+ "0-5000": '0-a-5000-pesos',
6
+ "5000-10000": '5000-a-10000-pesos',
7
+ "10000-15000": '10000-a-15000-pesos',
8
+ "15000-20000": '15000-a-20000-pesos',
9
+ "20000-30000": '20000-a-30000-pesos',
10
+ "30000-40000": '30000-a-40000-pesos',
11
+ "40000-50000": '40000-a-50000-pesos',
12
+ "50000-65000": '50000-a-65000-pesos',
13
+ "65000-80000": '65000-a-80000-pesos',
14
+ "80000-": 'mas-de-80000'
15
+ }.freeze
16
+ end
@@ -0,0 +1,59 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # finds jobs and returns simplified objects of them selfs
4
+ class Finder
5
+ attr_reader :jobs
6
+ def initialize(options = {})
7
+ @formatter = options[:formatter] || ChambaSearchMx::UrlFormatter.new
8
+ @pagination = options[:pagination] || ChambaSearchMx::Pagination.new
9
+ @search_page = options[:search_page] || ChambaSearchMx::SearchPage.new
10
+ @job = options[:job] || ChambaSearchMx::JobPage.new
11
+ end
12
+
13
+ def find(search, options = {})
14
+ @search = search
15
+ @options = options
16
+ validate_arguments
17
+ find_jobs
18
+ self
19
+ end
20
+
21
+ def validate_arguments
22
+ error_msg = 'search must be a non empty string'
23
+ raise ArgumentError, error_msg unless search_valid?
24
+ end
25
+
26
+ def search_valid?
27
+ if @search.class != String || @search.empty?
28
+ false
29
+ else
30
+ true
31
+ end
32
+ end
33
+
34
+ def find_jobs
35
+ @jobs = job_urls.map { |url| @job.load(url).data }
36
+ end
37
+
38
+ def job_urls
39
+ pagination_urls.map { |url| @search_page.load(url).job_urls }.flatten
40
+ end
41
+
42
+ def pagination_urls
43
+ @pagination.load(format_url).urls
44
+ end
45
+
46
+ def format_url
47
+ opts = search_options
48
+ @formatter.format @search, opts
49
+ end
50
+
51
+ def search_options
52
+ {
53
+ location: @options[:location] || 'default',
54
+ days: @options[:days] || 'default',
55
+ salary: @options[:salary] || 'default'
56
+ }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,23 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module ChambaSearchMx
5
+ ##
6
+ # loads web page using nokogiri
7
+ class HTMLPage
8
+ attr_reader :content
9
+ ##
10
+ # @param <hash> options
11
+ # @see ChambaSearchMx::BASE_URL
12
+ def initialize(opts = {})
13
+ @base_url = opts[:base_url] || ChambaSearchMx::BASE_URL
14
+ end
15
+
16
+ ##
17
+ # loads Kokogiri::HTML:Document as @content which can be read
18
+ # @param <string>
19
+ def load(url)
20
+ @content = Nokogiri::HTML open("#{@base_url}#{url}")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # cleaner job representation
4
+ class JobDecorator
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def businesses
10
+ @options[:businesses]
11
+ end
12
+
13
+ def company
14
+ @options[:company]
15
+ end
16
+
17
+ def contact_email
18
+ @options[:contact_email]
19
+ end
20
+
21
+ def contact_name
22
+ @options[:contact_name]
23
+ end
24
+
25
+ def description
26
+ @options[:description]
27
+ end
28
+
29
+ def sector
30
+ @options[:sector]
31
+ end
32
+
33
+ def title
34
+ @options[:title]
35
+ end
36
+
37
+ def url
38
+ @options[:url]
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,105 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # Job unique page
4
+ class JobPage
5
+ ##
6
+ # @param <hash> options
7
+ def initialize(opts = {})
8
+ @http = opts[:http] || ChambaSearchMx::HTMLPage.new
9
+ @job_decorator = opts[:job_decorator] || ChambaSearchMx::JobDecorator
10
+ end
11
+
12
+ ##
13
+ # @param <string> url
14
+ # @return <class> self
15
+ def load(url = '')
16
+ @url = url
17
+ @http.load @url
18
+ self
19
+ end
20
+
21
+ ##
22
+ # @return <ChambaSearchMx::JobDecorator> instance
23
+ def data
24
+ @job_decorator.new decorator_data
25
+ end
26
+
27
+ private
28
+
29
+ ##
30
+ # data used for @job_decorator
31
+ # @return <Hash>
32
+ def decorator_data
33
+ {
34
+ businesses: businesses,
35
+ company: company,
36
+ contact_email: contact_email,
37
+ contact_name: contact_name,
38
+ description: description,
39
+ sector: sector,
40
+ title: title,
41
+ url: @url
42
+ }
43
+ end
44
+
45
+ ##
46
+ # @return <string> title
47
+ def title
48
+ content.css('#tittlejob_jo h1').text
49
+ end
50
+
51
+ ##
52
+ # @return <string> company
53
+ def company
54
+ content.css('#tittlejob_jo span h3 span').text
55
+ end
56
+
57
+ ##
58
+ # @return <string> sector
59
+ def sector
60
+ content.css('#bg_triangle_ba dd:eq(2)').text
61
+ end
62
+
63
+ ##
64
+ # @return <string> businesses
65
+ def businesses
66
+ content.css('#bg_triangle_ba dd:eq(3)').text
67
+ end
68
+
69
+ ##
70
+ # @return <string> contact_name
71
+ def contact_name
72
+ contact_name_text.gsub(/contacto:/i, '').strip
73
+ end
74
+
75
+ ##
76
+ # @return <string> contact_email
77
+ def contact_email
78
+ contact_email_text.gsub(/correo:/i, '').strip
79
+ end
80
+
81
+ ##
82
+ # @return <string> description
83
+ def description
84
+ content.css('.txt2_jo').text
85
+ end
86
+
87
+ ##
88
+ # @return <string> contact_name_text
89
+ def contact_name_text
90
+ content.css('#contactData span[itemprop=name]').text
91
+ end
92
+
93
+ ##
94
+ # @return <string> contact_email_text
95
+ def contact_email_text
96
+ content.css('#contactData #mail_info').text
97
+ end
98
+
99
+ ##
100
+ # @return <class> Nokogiri::XML::Document
101
+ def content
102
+ @http.content
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,37 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # provides the url of the search pagination
4
+ class Pagination
5
+ attr_reader :urls
6
+ ##
7
+ # @param <hash> opts
8
+ # @see ChambaSearchMx::BASE_URL
9
+ def initialize(opts = {})
10
+ @urls = []
11
+ @http = opts[:http] || ChambaSearchMx::HTMLPage.new
12
+ end
13
+
14
+ ##
15
+ # @param <string> search page url
16
+ # @return <class> self
17
+ def load(url)
18
+ @http.load url
19
+ @urls = find_pages.map! { |p| p == '#' ? url : p }
20
+ self
21
+ end
22
+
23
+ private
24
+
25
+ ##
26
+ # @return <array> of strings
27
+ def find_pages
28
+ page_links.map { |p| p.css('a').attribute('href').text }
29
+ end
30
+
31
+ ##
32
+ # @return <array> of nokogiri objects
33
+ def page_links
34
+ @http.content.css('#numeracion_sr').css('.actual_m,.pagina_m')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # search landing page
4
+ class SearchPage
5
+ def initialize(opts = {})
6
+ @http = opts[:http] || ChambaSearchMx::HTMLPage.new
7
+ end
8
+
9
+ ##
10
+ # @param <string> search page url
11
+ def load(url)
12
+ @http.load url
13
+ self
14
+ end
15
+
16
+ ##
17
+ # @return <array> of strings
18
+ def job_urls
19
+ job_elements.map do |job|
20
+ job.css('.title_modn_sr a').attribute('href').value
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ ##
27
+ # Nokogiri:XML:NodeSet instance
28
+ def job_elements
29
+ @http.content.css('#results_sr').css('.job-normal,.standoutnor-jobn')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,96 @@
1
+ module ChambaSearchMx
2
+ ##
3
+ # it formats urls base on hash options
4
+ # @see ChambaSearchMx::LOCATIONS
5
+ # @see ChambaSearchMx::SALARIES
6
+ # @see ChambaSearchMx::DAYS
7
+ class UrlFormatter
8
+ def initialize(opts = {})
9
+ @locations = opts[:locations] || ChambaSearchMx::LOCATIONS
10
+ @salaries = opts[:salaries] || ChambaSearchMx::SALARIES
11
+ @days = opts[:days] || ChambaSearchMx::DAYS
12
+ end
13
+
14
+ ##
15
+ # @param <query> string "web developer"
16
+ # @params *<options> :location, :salary, :days
17
+ def format(query, *options)
18
+ @query = query
19
+ @options = options.inject({}) { |acc, elem| acc.merge! elem }
20
+ "/#{location}#{salary}#{days}/#{query_slug}"
21
+ end
22
+
23
+ private
24
+
25
+ ##
26
+ # converts query string into a url slug
27
+ def query_slug
28
+ remove_white_spaces(remove_spaces(downcase))
29
+ end
30
+
31
+ ##
32
+ # string downcase
33
+ def downcase
34
+ @query.downcase
35
+ end
36
+
37
+ ##
38
+ # replace space for -
39
+ def remove_spaces(str)
40
+ str.strip.tr(' ', '-')
41
+ end
42
+
43
+ ##
44
+ # removes extra white spaces
45
+ def remove_white_spaces(str)
46
+ str.gsub(/[^\w-]/, '')
47
+ end
48
+
49
+ ##
50
+ # returns the location string based on options or default
51
+ # @raise Argument error when option is not valid
52
+ def location
53
+ return @locations[:default] unless @options[:location]
54
+ error = proc { argument_error 'location', @locations }
55
+ error.call unless option_exists?(@locations, :location)
56
+ @locations[@options[:location].to_sym]
57
+ end
58
+
59
+ ##
60
+ # returns the salary string based on options
61
+ # @raise Argument error when option is not valid
62
+ def salary
63
+ return unless @options.key? :salary
64
+ return if @options[:salary] == 'default'
65
+ error = proc { argument_error 'salary', @salaries }
66
+ error.call unless option_exists?(@salaries, :salary)
67
+ "/#{@salaries[@options[:salary].to_sym]}"
68
+ end
69
+
70
+ ##
71
+ # returns the days string based on options
72
+ # @raise Argument error when option is not valid
73
+ def days
74
+ return unless @options.key? :days
75
+ return if @options[:days] == 'default'
76
+ error = proc { argument_error 'days', @days }
77
+ error.call unless option_exists?(@days, :days)
78
+ "/#{@days[@options[:days].to_s.to_sym]}"
79
+ end
80
+
81
+ ##
82
+ # Argument error parser
83
+ def argument_error(arg_name, available_options)
84
+ msg = "#{arg_name}: {OPTION} |"
85
+ msg += "avalilable options #{available_options.keys.join(', ')}"
86
+ raise ArgumentError, msg
87
+ end
88
+
89
+ ##
90
+ # gets value from the options hash
91
+ # @returm <boolean>
92
+ def option_exists?(hash, key)
93
+ hash.key? @options[key].to_s.to_sym
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module ChambaSearchMx
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chamba_search_mx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ricardo Rivas G.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-mocks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '9.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '9.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nyan-cat-formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.6'
125
+ description: Job Finder for Mexico
126
+ email:
127
+ - richistron@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".editorconfig"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".ruby-version"
137
+ - ".travis.yml"
138
+ - ".vimrc"
139
+ - CHANGELOG.md
140
+ - Gemfile
141
+ - LICENSE.txt
142
+ - README.md
143
+ - Rakefile
144
+ - bin/console
145
+ - bin/setup
146
+ - chamba_search_mx.gemspec
147
+ - lib/chamba_search_mx.rb
148
+ - lib/chamba_search_mx/factories/base_url.rb
149
+ - lib/chamba_search_mx/factories/days.rb
150
+ - lib/chamba_search_mx/factories/locations.rb
151
+ - lib/chamba_search_mx/factories/salaries.rb
152
+ - lib/chamba_search_mx/finder.rb
153
+ - lib/chamba_search_mx/html_page.rb
154
+ - lib/chamba_search_mx/job_decorator.rb
155
+ - lib/chamba_search_mx/job_page.rb
156
+ - lib/chamba_search_mx/pagination.rb
157
+ - lib/chamba_search_mx/search_page.rb
158
+ - lib/chamba_search_mx/url_formatter.rb
159
+ - lib/chamba_search_mx/version.rb
160
+ homepage:
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.5.1
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: This gem allows you to search jobs from the internets
184
+ test_files: []