jobless 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9699e3b94b093d9e0e5199ec761d74d9a15a7d0
4
- data.tar.gz: 6f824c07692d4de21f2bac5028e1a0aaf9ba476c
3
+ metadata.gz: 4ab4f6cc3a65172601551b7570f094aa3deefff3
4
+ data.tar.gz: 7bb2b7a72f4b4986453be4bfb5207a2ab726add8
5
5
  SHA512:
6
- metadata.gz: 225722fda5088e7e71007638021181a388390edc24319693abfdc4602c26e79370350f481735866e89f24e54f5f32e9b4f0ef9b8bbc6c32b69a561be2e1a4d95
7
- data.tar.gz: 18c95ce194192c93d87908a62a335c8a51d9c583e4720d0ab4d076d6ff0be54d0cf5ee69070b2934f1ece9c51e38fe2b2bee0339fb8bc64f0c96e84c894b4c71
6
+ metadata.gz: f6f073e04dd2b9b7e60573dd1c6f3024c61cbc1be5d8ab2ae037bd30c8bba2ed365fdc50e47ba14924256c6e15c496ddc869fd9818b6540d8a9d52eebec3646f
7
+ data.tar.gz: 8227bfc3e83271e04f24dc116f875842188d9e2361529ff05938d3cee0ad7cd913a66fa03fbfd01a9d74ee449ca99d54223957994777ccf168e4c9a26117c66f
data/lib/document.rb CHANGED
@@ -1,9 +1,25 @@
1
1
  require 'erb'
2
+ require 'active_support/core_ext/string/inflections'
2
3
 
3
4
  module Jobless
4
5
  class Document
5
6
  attr_reader :groups, :data
6
7
 
8
+ PERSONAL_ATTRIBUTES = %w(
9
+ name
10
+ email
11
+ location
12
+ address
13
+ homepage
14
+ )
15
+
16
+ GROUP_NAMES = %w(
17
+ employment
18
+ education
19
+ open_source
20
+ other_experience
21
+ )
22
+
7
23
  def initialize
8
24
  @data = {}
9
25
  @groups = []
@@ -12,7 +28,7 @@ module Jobless
12
28
  end
13
29
 
14
30
  # Define methods for setting personal data
15
- %w(name location address homepage email).each do |attribute_name|
31
+ PERSONAL_ATTRIBUTES.each do |attribute_name|
16
32
  define_method(attribute_name) do |attribute=nil|
17
33
  if attribute
18
34
  @data[attribute_name.to_sym] = attribute
@@ -22,26 +38,16 @@ module Jobless
22
38
  end
23
39
  end
24
40
 
25
- def group(name, type=nil, &block)
26
- group = Group.new(name, type)
41
+ def group(name, &block)
42
+ group = Group.new(name)
27
43
  group.instance_eval &block
28
44
  @groups.push group
29
45
  end
30
-
31
- def employment(&block)
32
- group("Employment", :employment, &block)
33
- end
34
-
35
- def education(&block)
36
- group("Education", :education, &block)
37
- end
38
-
39
- def open_source(&block)
40
- group("Open Source", :open_source, &block)
41
- end
42
-
43
- def other_experience(&block)
44
- group("Other Experience", :other_experience, &block)
46
+
47
+ GROUP_NAMES.each do |group_name|
48
+ define_method(group_name) do |&block|
49
+ group(group_name.titleize, &block)
50
+ end
45
51
  end
46
52
 
47
53
  def template(template)
data/lib/errors.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Jobless
2
+ module Error
3
+ class GitHubApi < StandardError; end
4
+ end
5
+ end
data/lib/group.rb CHANGED
@@ -1,10 +1,14 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'net/http'
3
+ require 'JSON'
4
+
1
5
  module Jobless
2
6
  class Group
3
7
  attr_reader :items, :name, :type
4
8
 
5
- def initialize(name, type=nil)
9
+ def initialize(name)
6
10
  @name = name
7
- @type = type
11
+ @type = name.parameterize
8
12
  @items = []
9
13
  end
10
14
 
@@ -15,5 +19,33 @@ module Jobless
15
19
  end
16
20
 
17
21
  alias_method :entry, :item
22
+
23
+ def github_repo(url, &block)
24
+ repo_name = url.match(/([^\/]*)\/([^\/]*)$/).captures.join("/")
25
+ repo_data = fetch_github_repo_data(repo_name)
26
+ item = Item.new
27
+ item.instance_eval do
28
+ title repo_data['name']
29
+ description repo_data['description']
30
+ homepage repo_data['html_url']
31
+ end
32
+ item.instance_eval &block if block_given?
33
+ @items.push item
34
+ end
35
+
36
+ private
37
+
38
+ def fetch_github_repo_data(repo_name)
39
+ url = "https://api.github.com/repos/#{repo_name}"
40
+ uri = URI.parse(url)
41
+ response = Net::HTTP.get_response(uri)
42
+ if response.code == "200"
43
+ JSON.parse(response.body)
44
+ else
45
+ raise Error::GitHubApi, "GitHub API responded with an unexpected "\
46
+ "status: '#{response.code}', while trying to fetch following "\
47
+ "repository: '#{repo_name}'."
48
+ end
49
+ end
18
50
  end
19
51
  end
data/lib/item.rb CHANGED
@@ -2,13 +2,23 @@ module Jobless
2
2
  class Item
3
3
  attr_reader :data, :bulletins
4
4
 
5
+ PERSONAL_ATTRIBUTES = %w(
6
+ title
7
+ company
8
+ homepage
9
+ technologies
10
+ description
11
+ start_date
12
+ end_date
13
+ )
14
+
5
15
  def initialize
6
16
  @data = {}
7
17
  @bulletins = []
8
18
  end
9
19
 
10
20
  # Define methods for setting personal data
11
- %w(title company homepage technologies description start_date end_date).each do |attribute_name|
21
+ PERSONAL_ATTRIBUTES.each do |attribute_name|
12
22
  define_method(attribute_name) do |attribute=nil|
13
23
  if attribute
14
24
  @data[attribute_name.to_sym] = attribute
data/lib/jobless.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative 'document'
2
2
  require_relative 'group'
3
3
  require_relative 'item'
4
+ require_relative 'errors'
4
5
 
5
6
  module Jobless
6
7
  def self.cv(filename = "cv.html", &block)
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filip Defar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-20 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
13
27
  description: Jobless is a simple DSL for creating a CV in HTML format.
14
28
  email: filip.defar@gmail.com
15
29
  executables: []
@@ -17,6 +31,7 @@ extensions: []
17
31
  extra_rdoc_files: []
18
32
  files:
19
33
  - lib/document.rb
34
+ - lib/errors.rb
20
35
  - lib/group.rb
21
36
  - lib/item.rb
22
37
  - lib/jobless.rb