common_tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0042d9af59bbb4270bbaefbcfd969cf6a7f3a3b9
4
+ data.tar.gz: 5b7e52deb4a1d5425e4d0eab153fe5ac523851bd
5
+ SHA512:
6
+ metadata.gz: 39105abeb746297c768e0a8cdb55358408b09d569bc7e5c18140476938d681adaee95e0446d880dbb553c65076bb9b5d94b5a8075ccddd5f964db16718ab6e7f
7
+ data.tar.gz: 5c64ed6c7e8245e890c58a7f62fd642d10f11e16066023d19dfb721e0283733bfcf602599891e32bc90bd21afd0ce7f71e4a504b3a4000c25852b2f52490e1f7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in common_tools.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Instructor Tools: Common Tools
2
+
3
+ Welcome to the instructor tools Common Tools gem. This gem will exist as a dependency of [Instructor-Tools](https://github.com/flatiron-labs/Instructor-tools-gem).
4
+
5
+ The purpose of this gem is to provide instructors with a resource for commonly used tools (parsing a batch csv into student objects) that can be required as a dependency instead of re-writing the same code.
6
+
7
+ ##Instructions
8
+
9
+ To include this gem add the below line to your projects gemfile:
10
+
11
+ ```
12
+ gem 'instructor-tools-common-tools'
13
+ ```
14
+
15
+ ###Functionality
16
+ This gem contains several functions see below for specific details
17
+
18
+ * CSV to JSON Parser
19
+ * `CommonTools.parse_csv('complete/path/to/file')`
20
+ * This will parse your csv file into a JSON string
21
+
22
+ ## Contributing
23
+ To contribute to this gem:
24
+
25
+ * Fork the [repo](https://github.com/flatiron-labs/instructor-tools-common-tools)
26
+ * Make your contributions and set up whatever tests are necessary
27
+ * Wrap any new functionality in `CommonTools` class methods
28
+ * Submit a pull request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "common_tools"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'common_tools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "common_tools"
8
+ spec.version = CommonTools::VERSION
9
+ spec.authors = ["BenjaGross"]
10
+ spec.email = ["ben@flatironschool.com"]
11
+
12
+ spec.summary = %q{Common Tools and scripts for Flatiron School Instructors}
13
+ spec.description = %q{Includes often used scripts to help instructors work}
14
+ spec.homepage = "https://github.com/flatiron-labs/instructor-tools-common-tools"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ # if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
23
+ # end
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.8"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'csv'
2
+ require 'json'
3
+ require 'pry'
4
+ require_relative 'student'
5
+
6
+ class Parser
7
+
8
+ def self.build_batch(file)
9
+ headers = CSV.read(file, headers: true).headers
10
+ Student.build_attributes(headers)
11
+ CSV.foreach(file, headers: true).map do |row|
12
+ make_student_attributes(row) unless row[0] == "first_name" || row[0].nil?
13
+ end.to_json
14
+ end
15
+
16
+ def self.make_student_attributes(row)
17
+ Student.new(row.to_h)
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module SayHello
2
+
3
+ def say_hello(name)
4
+ "Hello #{name}"
5
+ end
6
+
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+ class Student
3
+
4
+ def initialize(args)
5
+ args.each do |key, value|
6
+ self.public_send("#{key}=", value )
7
+ end
8
+ end
9
+
10
+ def self.build_attributes(headers)
11
+ headers.each do |header|
12
+ attr_accessor header.to_sym
13
+ end
14
+ end
15
+
16
+ def to_json(args)
17
+ hash = {}
18
+ self.instance_variables.each{ |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
19
+ hash.to_json
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ class CommonTools
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "common_tools/version"
2
+ require_relative "common_tools/say_hello"
3
+ require_relative "common_tools/parser"
4
+
5
+
6
+ class CommonTools
7
+ extend SayHello
8
+
9
+ def self.parse_csv(csv_file)
10
+ Parser.build_batch(csv_file)
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: common_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BenjaGross
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-07 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
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
+ description: Includes often used scripts to help instructors work
42
+ email:
43
+ - ben@flatironschool.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - common_tools.gemspec
57
+ - lib/common_tools.rb
58
+ - lib/common_tools/parser.rb
59
+ - lib/common_tools/say_hello.rb
60
+ - lib/common_tools/student.rb
61
+ - lib/common_tools/version.rb
62
+ homepage: https://github.com/flatiron-labs/instructor-tools-common-tools
63
+ licenses: []
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Common Tools and scripts for Flatiron School Instructors
85
+ test_files: []