dropmire 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module Dropmire
2
+ class Error < StandardError
3
+
4
+ attr_reader :message, :text
5
+
6
+ def initialize(message=nil, text=nil)
7
+ super(message)
8
+
9
+ @text = text
10
+ @message = "#{message} - #{text}"
11
+ end
12
+
13
+ def to_s
14
+ "Error: #{@message}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Dropmire
2
+ class ParseError < Error
3
+ def initialize(message="Malformed input string", text=nil)
4
+ super(message, text)
5
+ end
6
+
7
+ def to_s
8
+ "Parse" + super
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ Dir[File.dirname(__FILE__) + '/error/*.rb'].each do |file|
2
+ require file
3
+ end
@@ -1,4 +1,5 @@
1
1
  require 'dropmire/ext/string'
2
+ require 'dropmire/validator'
2
3
 
3
4
  module Dropmire
4
5
  class Parser
@@ -16,6 +17,8 @@ module Dropmire
16
17
  def initialize(text, options = {})
17
18
  @text = text
18
19
  @attrs = {}
20
+
21
+ Dropmire::Validator.new(@text)
19
22
  end
20
23
 
21
24
  def attrs
@@ -0,0 +1,20 @@
1
+ require 'dropmire/error/parse_error'
2
+
3
+ module Dropmire
4
+ class Validator
5
+ def initialize(text)
6
+ @text = text
7
+ validate
8
+ end
9
+
10
+ def validate
11
+ if regex.match(@text).to_s == ""
12
+ raise ParseError.new("Malformed input string", @text)
13
+ end
14
+ end
15
+
16
+ def regex
17
+ /%\w*\^\w*\$\w*\$\w*\^[\w\s]*\^\s*\?;\d*=\d*=\?\+\!\s*\d*[\s\w]*\?/
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Dropmire
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/dropmire.rb CHANGED
@@ -1,6 +1,3 @@
1
- require "dropmire/identity"
2
- require "dropmire/parser"
3
- require "dropmire/version"
4
-
5
- module Dropmire
1
+ Dir[File.dirname(__FILE__) + '/dropmire/*.rb'].each do |file|
2
+ require file
6
3
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dropmire::Validator do
4
+
5
+ context "validates corrext regex" do
6
+ it "doesnt raise exception" do
7
+ @text1 = """%FLTALLAHASSEE^JACOBSEN$CONNOR$ALAN^6357 SINKOLA DR^ ?;6360101021210193207=1506199306070=?+! 323124522 E 1602 ECCECC00000?"""
8
+ expect { Dropmire::Validator.new(@text1) }.to_not raise_error
9
+ end
10
+ end
11
+
12
+ context "validates corrext regex" do
13
+ it "raises exception" do
14
+ @text2 = """%FLTALLAHASSEEJACOBSEN$CONNOR$ALAN^6357 SINKOLA DR^ ?;6360101021210193207=1506199306070=?+! 323124522 E 1602 ECCECC00000?"""
15
+ expect { Dropmire::Validator.new(@text2) }.to raise_error
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropmire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-02 00:00:00.000000000 Z
12
+ date: 2014-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -73,13 +73,18 @@ files:
73
73
  - Rakefile
74
74
  - dropmire.gemspec
75
75
  - lib/dropmire.rb
76
+ - lib/dropmire/error/error.rb
77
+ - lib/dropmire/error/parse_error.rb
78
+ - lib/dropmire/errors.rb
76
79
  - lib/dropmire/ext/string.rb
77
80
  - lib/dropmire/identity.rb
78
81
  - lib/dropmire/parser.rb
82
+ - lib/dropmire/validator.rb
79
83
  - lib/dropmire/version.rb
80
84
  - spec/identity_spec.rb
81
85
  - spec/parser_spec.rb
82
86
  - spec/spec_helper.rb
87
+ - spec/validator_spec.rb
83
88
  homepage: https://github.com/connorjacobsen/dropmire
84
89
  licenses:
85
90
  - Apache-2.0
@@ -109,3 +114,4 @@ test_files:
109
114
  - spec/identity_spec.rb
110
115
  - spec/parser_spec.rb
111
116
  - spec/spec_helper.rb
117
+ - spec/validator_spec.rb