scaffolding 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: 05ca5dfe623014366cb3136166fa400a1d7aa520
4
+ data.tar.gz: 84dbe3611ab52399084749d1557c2daddc9f141c
5
+ SHA512:
6
+ metadata.gz: c9518fbe8a386f226c6e22552d11f299149a4a2719be9d4873de789e22e92af9331156b0514af63bfcd96f49036615eddd58dedcf627848a5d451880858c1ec1
7
+ data.tar.gz: 38b2a1a3ee1fdca11b8f213f570e53848b5078efb19de3524d0370260763a24d722b55798b111cd53643faeb70cc5b28ccd539ccf45ce7835478a09069493bd3
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/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scaffolding.gemspec
4
+ gemspec
5
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jordan-deJong
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,38 @@
1
+ # Scaffolding
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/scaffolding`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'scaffolding'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scaffolding
20
+
21
+ ## Usage
22
+
23
+
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/scaffolding. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'scaffolding'
7
+ ARGV.clear
8
+ IRB.start
9
+ end
10
+
11
+ task :b do |t|
12
+ require 'scaffolding'
13
+ puts "Enter a relative file name to build the scaffold"
14
+ file = STDIN.gets.chomp
15
+ Scaffolding.build('C:\Users\jdejong\Desktop\Windows.csv')
16
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "scaffolding"
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,63 @@
1
+ module Scaffolding
2
+ module Importer
3
+ class Base
4
+
5
+ def initialize(file = "")
6
+ @data = valid_data?(file)
7
+ @file_name = File.basename(file, ".*" ).to_s.split.join.downcase
8
+ @code_string = "rails g scaffold #{@file_name}"
9
+ @scaffolding = {}
10
+ @errors = []
11
+ end
12
+
13
+ def errors
14
+ @errors
15
+ end
16
+
17
+ def valid_data?(file)
18
+ unless file == ""
19
+ if [".csv", ".xls", ".xlsx"].include? File.extname(file)
20
+ File.read(utf8_encode(file))
21
+ else
22
+ @errors << "Unknown file type: #{File.extname(file)}"
23
+ false
24
+ end
25
+ else
26
+ @errors << "No file selected"
27
+ false
28
+ end
29
+ end
30
+
31
+ def utf8_encode(s)
32
+ s.force_encoding(Encoding::ISO_8859_1).encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
33
+ end
34
+
35
+ # def camelize(term, uppercase_first_letter = true)
36
+ # string = term.to_s
37
+ # if uppercase_first_letter
38
+ # string = string.sub(/^[a-z\d]*/) { inflections.acronyms[$&] || $&.capitalize }
39
+ # else
40
+ # string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { $&.downcase }
41
+ # end
42
+ # string.gsub!(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
43
+ # string.gsub!(/\//, '::')
44
+ # string
45
+ # end
46
+
47
+ def code_string
48
+ process_data
49
+ @scaffolding.each do |k, v|
50
+ @code_string << " #{k}:#{v}"
51
+ end
52
+ @code_string
53
+ end
54
+
55
+ def self.process(file)
56
+ importer = self.new(file)
57
+ return importer.errors unless importer.errors.count == 0
58
+ importer.code_string.to_s + "; rake db:migrate"
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,50 @@
1
+ module Scaffolding
2
+ module Importer
3
+ class Excel < Scaffolding::Importer::Base
4
+ require 'CSV'
5
+
6
+ def initialize(file = "")
7
+ super
8
+ @headers = true
9
+ @col_seperator = ","
10
+ @row_number = 0
11
+ end
12
+
13
+ def process_data(data = @data)
14
+ CSV.parse(data, headers: @headers, col_sep: @col_seperator, skip_blanks: true) do |row|
15
+ setup_columns(row.to_h.keys) if @row_number == 0
16
+ @row_number += 1
17
+ begin
18
+ process_row(row.inject({}){|row,(k,v)| row[k.downcase.to_sym] = v; row})
19
+ rescue => e
20
+ @errors << "Unable to process row #{@row_number} Error: #{e}\n"
21
+ end #rescue block
22
+ end
23
+ scaffold_rank
24
+ @errors
25
+ end
26
+
27
+ def setup_columns(columns)
28
+ columns.each do |column|
29
+ @scaffolding[column.downcase.to_sym] = {string: 0, date: 0, integer: 0}
30
+ end
31
+ end
32
+
33
+ def process_row(row)
34
+ row.each do |column, data|
35
+ data_type = :string
36
+ data_type = :date if Date.parse(data) rescue data_type
37
+ data_type = :integer if Integer(data) rescue data_type
38
+ @scaffolding[column.to_sym][data_type] += 1
39
+ end
40
+ end
41
+
42
+ def scaffold_rank
43
+ @scaffolding.each do |scaffold, data_types|
44
+ @scaffolding[scaffold] = data_types.max_by{|k,v| v}[0]
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Scaffolding
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ require "scaffolding/version"
2
+
3
+ module Scaffolding
4
+ require 'pry'
5
+ require 'clipboard'
6
+
7
+ def self.build(file)
8
+ #'C:\Users\jdejong\Desktop\Windows.csv'
9
+ result = Scaffolding::Importer::Excel.process(file).to_s
10
+ puts result
11
+ # exec result
12
+ end
13
+ end
14
+
15
+ require 'scaffolding/importer/base'
16
+ require 'scaffolding/importer/excel'
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scaffolding/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scaffolding"
8
+ spec.version = Scaffolding::VERSION
9
+ spec.authors = ["Jordan-deJong"]
10
+ spec.email = ["jordan.dejong@me.com"]
11
+
12
+ spec.summary = %q{Generate a scaffold based on a CSV file.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
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
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scaffolding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan-deJong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-30 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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:
42
+ email:
43
+ - jordan.dejong@me.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/scaffolding.rb
57
+ - lib/scaffolding/importer/base.rb
58
+ - lib/scaffolding/importer/excel.rb
59
+ - lib/scaffolding/version.rb
60
+ - scaffolding.gemspec
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
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.7
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Generate a scaffold based on a CSV file.
85
+ test_files: []