parse_me 0.0.2

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.
@@ -0,0 +1,124 @@
1
+ require './spec/spec_helper'
2
+ require './lib/parse_me'
3
+
4
+ describe 'Transformations' do
5
+ subject{ParseMe::Transformations}
6
+
7
+ before :each do
8
+ class Dummy; include ParseMe::Transformations; end
9
+ @dummy = Dummy.new
10
+
11
+ subject.public_instance_methods.each do |pim|
12
+ subject.module_eval do
13
+ module_function pim
14
+ public pim
15
+ end
16
+ end
17
+ end
18
+
19
+ it 'should be defined' do
20
+ should be
21
+ end
22
+
23
+ describe 'ghost_decimal_scale' do
24
+ it 'should be' do
25
+ subject.method(:ghost_decimal_scale).should be
26
+ end
27
+
28
+ describe 'test case 1 (valid number, valid rule value)' do
29
+ it 'should properly transform the input' do
30
+ subject.ghost_decimal_scale('123456', 2).should eq(1234.56)
31
+ end
32
+
33
+ it 'should properly transform a slightly bigger input' do
34
+ subject.ghost_decimal_scale('12345678', '3').should eq(12345.678)
35
+ end
36
+
37
+ it 'should properly transform a smaller input' do
38
+ subject.ghost_decimal_scale('123', '4').should eq(0.0123)
39
+ end
40
+ end
41
+
42
+ describe 'test case 2 (valid number, invalid rule value)' do
43
+ it 'should properly transform the input' do
44
+ subject.ghost_decimal_scale('123456', 'i').should eq(123456)
45
+ end
46
+
47
+ it 'should raise an Exception' do
48
+ expect{subject.ghost_decimal_scale('12345678', Date.new)}.to raise_error(Exception)
49
+ end
50
+ end
51
+
52
+ describe 'test case 3 (invalid number, valid rule value)' do
53
+ it 'should raise an exeption' do
54
+ expect{subject.ghost_decimal_scale(File, 2)}.to raise_error(Exception)
55
+ end
56
+
57
+ it 'should raise an exeption' do
58
+ expect{subject.ghost_decimal_scale(Object, 4)}.to raise_error(Exception)
59
+ end
60
+ end
61
+
62
+ describe 'when used from a ParsedObject instance without labeled rows' do
63
+ before :each do
64
+ @source = 'Lorem Ipsum Dolor sit amet 1050000'
65
+ @source += 'Foo Bar Baz 1234567'
66
+ @source += 'John Doe Dong 0034000'
67
+ @rules = {
68
+ first: {required: true, length: 15},
69
+ second: {required: true, length: 10},
70
+ third: {required: true, length: 10},
71
+ income: {required: true, length: 7, ghost_decimal_scale: 2}
72
+ }
73
+ @parsed = ParseMe::FixedWidthParser.new.parse(@source, @rules)
74
+ end
75
+
76
+ it 'should properly transform the income attribute to 10500' do
77
+ @parsed[0].income.should eq(10500)
78
+ end
79
+
80
+ it 'should properly transform the income attribute to 12345.67' do
81
+ @parsed[1].income.should eq(12345.67)
82
+ end
83
+
84
+ it 'should properly transform the income attribute to 340' do
85
+ @parsed[2].income.should eq(340)
86
+ end
87
+ end
88
+
89
+ describe 'when used from a ParsedObject instance with labeled rows' do
90
+ before :each do
91
+ @source = '0This is a header This is a desc. '
92
+ @source += '1Lorem Ipsum Dolor sit amet 1050000'
93
+ @source += '1Foo Bar Baz 1234567'
94
+ @source += '1John Doe Dong 0034000'
95
+ @rules = {
96
+ "0" => {
97
+ header: {required: true, length: 20},
98
+ description: {required: true, length: 15},
99
+ filler: {length: 7}
100
+ },
101
+ "1" => {
102
+ first: {required: true, length: 15},
103
+ second: {required: true, length: 10},
104
+ third: {required: true, length: 10},
105
+ income: {required: true, length: 7, ghost_decimal_scale: 2}
106
+ }
107
+ }
108
+ @parsed = ParseMe::FixedWidthParser.new.parse(@source, @rules, labeled_rows: true)
109
+ end
110
+
111
+ it 'should properly transform the income attribute to 10500' do
112
+ @parsed[1].income.should eq(10500)
113
+ end
114
+
115
+ it 'should properly transform the income attribute to 12345.67' do
116
+ @parsed[2].income.should eq(12345.67)
117
+ end
118
+
119
+ it 'should properly transform the income attribute to 340' do
120
+ @parsed[3].income.should eq(340)
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,76 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe 'Validations' do
4
+ subject{ParseMe::Validations}
5
+
6
+ before :each do
7
+ subject.public_instance_methods.each do |pim|
8
+ subject.module_eval do
9
+ module_function pim
10
+ public pim
11
+ end
12
+ end
13
+ end
14
+
15
+ it 'should be' do
16
+ should be
17
+ end
18
+
19
+ describe 'length' do
20
+ it 'should be' do
21
+ subject.method(:length).should be
22
+ end
23
+
24
+ describe 'proper input' do
25
+ before :each do
26
+ @input = '25 characters long string'
27
+ end
28
+
29
+ it 'should be truthy with length 25' do
30
+ subject.length(@input, 25).should be(true)
31
+ end
32
+
33
+ it 'should be falsy with length 24' do
34
+ subject.length(@input, 24).should be(false)
35
+ end
36
+
37
+ it 'should be truthy with length 35' do
38
+ subject.length(@input, 35).should be(true)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe 'required' do
44
+ it 'should be' do
45
+ subject.method(:required).should be
46
+ end
47
+
48
+ describe 'true' do
49
+ it 'should be truthy with a regular string' do
50
+ subject.required('FooBar', true).should be(true)
51
+ end
52
+
53
+ it 'should be falsy with a whitespace only string' do
54
+ subject.required(' ', true).should be(false)
55
+ end
56
+
57
+ it 'should be falsy with an empty string' do
58
+ subject.required('', true).should be(false)
59
+ end
60
+ end
61
+
62
+ describe 'false' do
63
+ it 'should be truthy with a regular string' do
64
+ subject.required('FooBar', false).should be(true)
65
+ end
66
+
67
+ it 'should be truthy with a whitespace only string' do
68
+ subject.required(' ', false).should be(true)
69
+ end
70
+
71
+ it 'should be truthy with an empty string' do
72
+ subject.required('', false).should be(true)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1 @@
1
+ require './spec/spec_helper'
@@ -0,0 +1 @@
1
+ require './spec/spec_helper'
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parse_me
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Serge Morales
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Plain text file parser
15
+ email:
16
+ - i.serge23@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rvmrc
23
+ - .travis.yml
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/parse_me.rb
29
+ - lib/parse_me/fixed_width_parser.rb
30
+ - lib/parse_me/input_splitting.rb
31
+ - lib/parse_me/input_splitting/fixed.rb
32
+ - lib/parse_me/input_splitting/fixed/base.rb
33
+ - lib/parse_me/input_splitting/fixed/labels.rb
34
+ - lib/parse_me/input_splitting/var.rb
35
+ - lib/parse_me/parsed_object.rb
36
+ - lib/parse_me/transformations.rb
37
+ - lib/parse_me/validations.rb
38
+ - lib/parse_me/var_width_parser.rb
39
+ - lib/parse_me/version.rb
40
+ - parse_me.gemspec
41
+ - spec/fixed_width/input_splitting_spec.rb
42
+ - spec/fixed_width/parser_spec.rb
43
+ - spec/namespace_spec.rb
44
+ - spec/parsed_object/parsed_object_spec.rb
45
+ - spec/spec_helper.rb
46
+ - spec/transformations/basic_spec.rb
47
+ - spec/validation/basic_spec.rb
48
+ - spec/validation/date_spec.rb
49
+ - spec/validation/numeric_spec.rb
50
+ homepage: https://github.com/sergelerator/parse_me
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ segments:
63
+ - 0
64
+ hash: 1587971647518469554
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ segments:
72
+ - 0
73
+ hash: 1587971647518469554
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.24
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Parse your fixed or variable width plain text files using your own custom
80
+ layouts, easily validate and retrieve your data.
81
+ test_files:
82
+ - spec/fixed_width/input_splitting_spec.rb
83
+ - spec/fixed_width/parser_spec.rb
84
+ - spec/namespace_spec.rb
85
+ - spec/parsed_object/parsed_object_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/transformations/basic_spec.rb
88
+ - spec/validation/basic_spec.rb
89
+ - spec/validation/date_spec.rb
90
+ - spec/validation/numeric_spec.rb