magic_mountain 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODkwYjVhNGJhOTc1YjdmZmY3NTNlNWEzNTJkM2Y2Mjk2ZDNkZTEyMQ==
5
+ data.tar.gz: !binary |-
6
+ N2U5MjEzNjJmMjVmMzVhYzFlODYyZGU0ZTRiNDJiZGEwYTQ0MjYyYw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MzI1ZTFlNThiMmEyOGM3N2ExN2NiZDM0MmNlZjcwYmZmN2ZlMzg0MTYzYzhj
10
+ OTIyNjJiMjFhOGIyZTA3YzFkNjI5Y2E0ZmFhMzFhMDYwZjQzN2M5YjVmNmVm
11
+ MzMyMjI2NDgzNTc1NGE5MDVmYTQzMGEyNDQ4MmU5NGQyODE2NzI=
12
+ data.tar.gz: !binary |-
13
+ Zjg0YjE0N2UzZmUxZDIzZGZkYzlkYjkxMzE0Njk5ZjNiMzlmYmIwMmZmODBl
14
+ ZTkwNjE1ZGI0MDU3MjE5YzllMGE1MzNhMjdjMjg2OTk2NjA3YzJmMjA5Y2Ux
15
+ YjgzNTI4MjUyYzZhNWUxYWYzNzMzN2JlZDU3Y2M4YmRjNGYxZGQ=
@@ -1,39 +1,64 @@
1
- require 'csv'
2
1
  require 'fileutils'
3
2
  require 'keepass-password-generator'
4
3
 
5
4
  module MagicMountain
6
- class FileFormater
7
- def self.generate_pass
8
- KeePass::Password.generate('[A]{8}', :remove_lookalikes => true)
9
- end
5
+ class FileFormater
6
+ def self.generate_pass
7
+ KeePass::Password.generate('[A]{8}', :remove_lookalikes => true)
8
+ end
10
9
 
11
- def self.format_file_to_csv(file_name, headers)
12
- raw_file = File.open( file_name, "rb:UTF-16LE" )
13
- formated_file_name = 'formated-' + file_name
14
- formated_file = File.open( formated_file_name, 'w')
10
+ def self.is_cursed?(file_name)
11
+ begin
12
+ CSV.read(file_name)
13
+ rescue ArgumentError => e
14
+ return true if e.message == "invalid byte sequence in UTF-8"
15
+ puts e.inspect
16
+ return false
17
+ rescue Exception => e
18
+ puts e.inspect
19
+ return false
20
+ end
21
+ return false
22
+ end
15
23
 
16
- formated_file.write("#{headers.join(',')}\n")
17
-
18
- while line = raw_file.gets
19
- line = line.encode("UTF-8").gsub("\r","\n").gsub("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
20
- content = line.split("\n")
21
- content.each do |line|
22
- fields = line.split(",")
23
- full_row = "#{line},#{generate_pass},#{generate_pass}\n"
24
- formated_file.write(full_row) if fields.size + 2 == headers.size
25
- end
26
- end
27
- raw_file.close
24
+ def self.curse_name?(file_name)
25
+ raw_file = File.open( file_name, "rb:UTF-16LE" )
26
+ max_num_of_fields = 0
27
+ while line = raw_file.gets
28
+ content = line.bytes.to_a.pack('c*').split("\r")
29
+ content.each do |line|
30
+ fields = line.split(",")
31
+ max_num_of_fields = fields.size if fields.size > max_num_of_fields
28
32
  end
33
+ end
34
+ raw_file.close
35
+ case max_num_of_fields
36
+ when 14
37
+ "need_account"
38
+ when 17
39
+ "new_students"
40
+ else
41
+ max_num_of_fields
42
+ end
43
+ end
29
44
 
30
- def self.valid_csv?(file)
31
- begin
32
- CSV.parse(file) { |row| }
33
- true
34
- rescue CSV::MalformedCSVError
35
- false
36
- end
45
+ def self.break_curse(file_name, spell)
46
+ healed_file_name = File.join(File.dirname(file_name), '..', 'healed/' + File.basename(file_name))
47
+ healed_file = File.open( healed_file_name, 'w')
48
+ healed_file.write("#{spell.join(',')}\n")
49
+ raw_file = File.open( file_name, "rb:UTF-16LE" )
50
+ while line = raw_file.gets
51
+ #content = line.bytes.to_a.pack('c*').split("\r")
52
+ line = line.encode("UTF-8").gsub("\r","\n").gsub("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
53
+ content = line.split("\n")
54
+ content.each do |line|
55
+ fields = line.split(",")
56
+ full_row = "#{line},#{generate_pass},#{generate_pass}\n"
57
+ healed_file.write(full_row) if fields.size + 2 == spell.size and fields[0].gsub("\"","").to_i > 0
37
58
  end
59
+ end
60
+ raw_file.close
38
61
  end
62
+
63
+ end
39
64
  end
@@ -1,3 +1,3 @@
1
1
  module MagicMountain
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic_mountain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mauro Morales
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-27 00:00:00.000000000 Z
11
+ date: 2013-08-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: keepass-password-generator
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -63,33 +58,26 @@ files:
63
58
  - spec/magic_mountain_spec.rb
64
59
  homepage: ''
65
60
  licenses: []
61
+ metadata: {}
66
62
  post_install_message:
67
63
  rdoc_options: []
68
64
  require_paths:
69
65
  - lib
70
66
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
67
  requirements:
73
68
  - - ! '>='
74
69
  - !ruby/object:Gem::Version
75
70
  version: '0'
76
- segments:
77
- - 0
78
- hash: 1968793947114160041
79
71
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
72
  requirements:
82
73
  - - ! '>='
83
74
  - !ruby/object:Gem::Version
84
75
  version: '0'
85
- segments:
86
- - 0
87
- hash: 1968793947114160041
88
76
  requirements: []
89
77
  rubyforge_project:
90
- rubygems_version: 1.8.24
78
+ rubygems_version: 2.0.3
91
79
  signing_key:
92
- specification_version: 3
80
+ specification_version: 4
93
81
  summary: Convert Magic Mountain exported files to propper CSV
94
82
  test_files:
95
83
  - spec/magic_mountain_spec.rb