posifile 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/errors.rb +5 -6
- data/lib/posifile.rb +16 -6
- data/posifile.gemspec +1 -1
- data/tests/tests_change_name.rb +1 -1
- data/tests/tests_inheritances.rb +0 -1
- data/tests/tests_pos_attributes.rb +1 -1
- data/tests/tests_posifile.rb +8 -3
- data/tests/tests_set_spec_with_uppercase.rb +1 -1
- metadata +11 -10
data/lib/errors.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
class FieldsNotSpecified <
|
2
|
-
end
|
3
|
-
class
|
4
|
-
end
|
5
|
-
|
6
|
-
end
|
1
|
+
class FieldsNotSpecified < StandardError; end
|
2
|
+
class InvalidFieldName < StandardError; end
|
3
|
+
class InvalidAttrName < StandardError; end
|
4
|
+
class InvalidPositionFileFormat < StandardError; end
|
5
|
+
|
data/lib/posifile.rb
CHANGED
@@ -10,8 +10,14 @@ class Posifile
|
|
10
10
|
|
11
11
|
attr_accessor :data_file, :raw_content
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
|
13
|
+
def initialize(data_file_name_or_text)
|
14
|
+
if data_file_name_or_text.class == String
|
15
|
+
@data_file = data_file_name_or_text
|
16
|
+
elsif data_file_name_or_text .class == Hash
|
17
|
+
@file_content = [data_file_name_or_text[:text]]
|
18
|
+
else
|
19
|
+
raise InvalidPositionFileFormat, "Pass a file path or text."
|
20
|
+
end
|
15
21
|
|
16
22
|
check_specification_hash
|
17
23
|
file_content.each do |line|
|
@@ -167,11 +173,15 @@ class Posifile
|
|
167
173
|
end
|
168
174
|
|
169
175
|
def file_content
|
170
|
-
if
|
171
|
-
|
172
|
-
|
176
|
+
if @data_file
|
177
|
+
if raw_content.nil?
|
178
|
+
file = File.open(@data_file, "r")
|
179
|
+
@raw_content = file.readlines
|
180
|
+
end
|
181
|
+
return @raw_content
|
182
|
+
else
|
183
|
+
@file_content
|
173
184
|
end
|
174
|
-
@raw_content
|
175
185
|
end
|
176
186
|
|
177
187
|
# Get the value of a specifc position declared in the specification hash
|
data/posifile.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'posifile'
|
3
|
-
s.version = '0.2.
|
3
|
+
s.version = '0.2.5'
|
4
4
|
s.summary = 'Ruby library to make it easier to read position files. '
|
5
5
|
s.description = 'Ruby library to make it easier to read position files.'
|
6
6
|
s.files = `git ls-files`.split("\n")
|
data/tests/tests_change_name.rb
CHANGED
@@ -8,7 +8,7 @@ class TestsChangeName < Test::Unit::TestCase
|
|
8
8
|
|
9
9
|
def test_um
|
10
10
|
c = Client.new("samples/sample.txt")
|
11
|
-
assert_equal "parangaricotirimirru_aro",c.change_name("parangaricotirIMi*rr\&u a-r.o")
|
11
|
+
assert_equal "parangaricotirimirru_aro", c.change_name("parangaricotirIMi*rr\&u a-r.o")
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
data/tests/tests_inheritances.rb
CHANGED
@@ -7,7 +7,7 @@ class MultiLinesWithTwoSpecs3 < Posifile
|
|
7
7
|
|
8
8
|
# two specifications, for a multi-line file
|
9
9
|
lines_where 0..2, "001" do
|
10
|
-
set_specification( "color"=>13..22,"brand"=>3..12)
|
10
|
+
set_specification( "color" => 13..22, "brand" => 3..12)
|
11
11
|
set_attr_name :brand
|
12
12
|
end
|
13
13
|
end
|
data/tests/tests_posifile.rb
CHANGED
@@ -7,14 +7,12 @@ class NoSpec < Posifile
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class TestPosifile < Test::Unit::TestCase
|
10
|
-
# Here are general tests
|
11
10
|
|
12
11
|
include TestHelpers
|
13
12
|
|
14
13
|
def setup
|
15
14
|
create_sample_file
|
16
15
|
create_sample_file2
|
17
|
-
create_sample_invalid
|
18
16
|
end
|
19
17
|
|
20
18
|
def test_posifile
|
@@ -36,7 +34,7 @@ class TestPosifile < Test::Unit::TestCase
|
|
36
34
|
|
37
35
|
def test_field_value
|
38
36
|
c = Client.new("samples/sample.txt")
|
39
|
-
assert_equal "jose", c.field_value("name",{"name"=>0..10, "city"=>11..31, "country"=>32..42}, "jose new york brazil ")
|
37
|
+
assert_equal "jose", c.field_value("name", {"name" => 0..10, "city" => 11..31, "country" => 32..42}, "jose new york brazil ")
|
40
38
|
end
|
41
39
|
|
42
40
|
def test_higher
|
@@ -48,5 +46,12 @@ class TestPosifile < Test::Unit::TestCase
|
|
48
46
|
no_spec = NoSpec.new("samples/sample.txt")
|
49
47
|
end
|
50
48
|
end
|
49
|
+
|
50
|
+
def test_passing_position_file_as_text
|
51
|
+
client = Client.new(:text => File.open("samples/sample.txt").read)
|
52
|
+
|
53
|
+
assert_equal "jose", client.field_value("name", {"name" => 0..10, "city" => 11..31, "country" => 32..42}, "jose new york brazil ")
|
54
|
+
assert_equal "jose", client.name
|
55
|
+
end
|
51
56
|
|
52
57
|
end
|
@@ -11,7 +11,7 @@ class TestPosifile < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
def test_set_spec_with_uppercase
|
13
13
|
assert_raise(InvalidFieldName) do
|
14
|
-
SpecWithUppercase.set_specification("Name"=>0..10, "CITY"=>11..31,"country"=>32..42)
|
14
|
+
SpecWithUppercase.set_specification("Name" => 0..10, "CITY" => 11..31, "country" => 32..42)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posifile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Marco Antonio Fogaça Nogueira
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-26 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby library to make it easier to read position files.
|
15
15
|
email:
|
@@ -42,26 +42,27 @@ files:
|
|
42
42
|
- tests/validations/tests_validations.rb
|
43
43
|
homepage: http://github.com/marcofognog/posifile
|
44
44
|
licenses: []
|
45
|
-
post_install_message:
|
45
|
+
post_install_message:
|
46
46
|
rdoc_options: []
|
47
47
|
require_paths:
|
48
48
|
- lib
|
49
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
50
|
requirements:
|
52
51
|
- - ! '>='
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '0'
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
54
|
none: false
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
56
|
requirements:
|
58
57
|
- - ! '>='
|
59
58
|
- !ruby/object:Gem::Version
|
60
59
|
version: 1.3.7
|
60
|
+
none: false
|
61
61
|
requirements: []
|
62
|
-
rubyforge_project:
|
63
|
-
rubygems_version: 1.8.
|
64
|
-
signing_key:
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.15
|
64
|
+
signing_key:
|
65
65
|
specification_version: 3
|
66
66
|
summary: Ruby library to make it easier to read position files.
|
67
67
|
test_files: []
|
68
|
+
...
|