jsgoecke-echi_files 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/echi_files.gemspec +2 -2
- data/lib/echi_files.rb +25 -6
- data/test/test_echi_files.rb +20 -4
- metadata +2 -2
data/echi_files.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "echi_files"
|
3
|
-
s.version = "0.2.
|
4
|
-
s.date = "2009-01-
|
3
|
+
s.version = "0.2.1"
|
4
|
+
s.date = "2009-01-26"
|
5
5
|
s.summary = "Ruby Library for Processing Avaya ECHI Files"
|
6
6
|
s.description = "Ruby Library for processing External Call History (ECHI) files from the Avaya CMS"
|
7
7
|
s.authors = ["Jason Goecke"]
|
data/lib/echi_files.rb
CHANGED
@@ -1,14 +1,35 @@
|
|
1
|
+
# This library is used to process Avaya CMS ECHI Files
|
2
|
+
#
|
3
|
+
# Author:: Jason Goecke (mailto:jason@goecke.net)
|
4
|
+
# Copyright:: Copyright (c) 2009 Jason Goecke
|
5
|
+
# License:: Distributes under the MIT License
|
6
|
+
#
|
7
|
+
# This class contains the methods for processing both
|
8
|
+
# binary and ascii files from the Avaya CMS
|
9
|
+
|
1
10
|
require 'yaml'
|
2
11
|
require 'fastercsv'
|
3
12
|
|
4
13
|
class EchiFiles
|
5
14
|
|
15
|
+
#Load the associated schema definitions of the Avaya ECHI files
|
6
16
|
def initialize
|
7
17
|
@extended = YAML::load_file(File.expand_path(File.dirname(__FILE__) + "/extended-definition.yml"))
|
8
18
|
@standard = YAML::load_file(File.expand_path(File.dirname(__FILE__) + "/standard-definition.yml"))
|
9
19
|
end
|
10
20
|
|
11
|
-
#Method
|
21
|
+
#Method to determine if the file is binary or ASCII encoded
|
22
|
+
def detect_filetype(filehandle)
|
23
|
+
if filehandle.read(1).is_binary_data?
|
24
|
+
type = 'BINARY'
|
25
|
+
else
|
26
|
+
type = 'ASCII'
|
27
|
+
end
|
28
|
+
filehandle.rewind
|
29
|
+
return type
|
30
|
+
end
|
31
|
+
|
32
|
+
#Method for parsing the various datatypes from the binary ECHI file
|
12
33
|
def dump_binary(filehandle, type, length)
|
13
34
|
case type
|
14
35
|
when 'int'
|
@@ -48,7 +69,7 @@ class EchiFiles
|
|
48
69
|
return value
|
49
70
|
end
|
50
71
|
|
51
|
-
#Mehtod that performs the conversions
|
72
|
+
#Mehtod that performs the conversions of files
|
52
73
|
def convert_binary_file(filehandle, schema, extra_byte)
|
53
74
|
|
54
75
|
#Read header information first
|
@@ -145,7 +166,7 @@ class EchiFiles
|
|
145
166
|
#@format Whether this is the ECHI EXTENDED or STANDARD file format
|
146
167
|
#@extra_byte Set to true if you want to read an extra byte at the end of each record
|
147
168
|
#This method will return an array of hashes of the resulting data processed
|
148
|
-
def process_file(filehandle,
|
169
|
+
def process_file(filehandle, format, extra_byte)
|
149
170
|
|
150
171
|
#Set the appropriate schema format for standard or extended from the Avaya CMS
|
151
172
|
case format
|
@@ -156,7 +177,7 @@ class EchiFiles
|
|
156
177
|
end
|
157
178
|
|
158
179
|
#Process based on the filetype passed
|
159
|
-
case
|
180
|
+
case detect_filetype(filehandle)
|
160
181
|
when 'ASCII'
|
161
182
|
return convert_ascii_file(filehandle, schema)
|
162
183
|
when 'BINARY'
|
@@ -170,7 +191,6 @@ class EchiFiles
|
|
170
191
|
#@fields An array of fields to strip characters from
|
171
192
|
#@characters An Array of characters to be stripped
|
172
193
|
def strip_special_characters(data, fields, characters)
|
173
|
-
|
174
194
|
stripped_data = Array.new
|
175
195
|
data.each do |row|
|
176
196
|
fields.each do |field|
|
@@ -182,7 +202,6 @@ class EchiFiles
|
|
182
202
|
end
|
183
203
|
stripped_data << row
|
184
204
|
end
|
185
|
-
|
186
205
|
return stripped_data
|
187
206
|
end
|
188
207
|
|
data/test/test_echi_files.rb
CHANGED
@@ -8,6 +8,7 @@ class EchiFiles_Test < Test::Unit::TestCase
|
|
8
8
|
#Provide a filename to process as an argument on the commandline
|
9
9
|
binary_file = File.open(File.expand_path("test/example_binary_file"))
|
10
10
|
ascii_file = File.open(File.expand_path("test/example_ascii_file"))
|
11
|
+
|
11
12
|
@proper_unstripped = YAML::load(File.open(File.expand_path("test/proper_unstripped.yml")))
|
12
13
|
@proper_stripped = YAML::load(File.open(File.expand_path("test/proper_stripped.yml")))
|
13
14
|
@proper_ascii = YAML::load(File.open(File.expand_path("test/proper_ascii.yml")))
|
@@ -15,12 +16,17 @@ class EchiFiles_Test < Test::Unit::TestCase
|
|
15
16
|
#Create a new EchiFiles object
|
16
17
|
echi_handler = EchiFiles.new
|
17
18
|
|
19
|
+
#Set filetype details
|
20
|
+
@filetype_binary = echi_handler.detect_filetype(binary_file)
|
21
|
+
binary_file.rewind
|
22
|
+
@filetype_ascii = echi_handler.detect_filetype(ascii_file)
|
23
|
+
ascii_file.rewind
|
24
|
+
|
18
25
|
#Use this to process a binary file
|
19
|
-
file_type = 'BINARY'
|
20
26
|
format = 'EXTENDED'
|
21
27
|
#In some cases the extra_byte is needed
|
22
28
|
extra_byte = true
|
23
|
-
@binary_data = echi_handler.process_file(binary_file,
|
29
|
+
@binary_data = echi_handler.process_file(binary_file, format, extra_byte)
|
24
30
|
#If you need to strip in characters from the asaiuui field
|
25
31
|
@stripped_data = Array.new
|
26
32
|
@binary_data.each do |data|
|
@@ -28,14 +34,23 @@ class EchiFiles_Test < Test::Unit::TestCase
|
|
28
34
|
end
|
29
35
|
|
30
36
|
#Use this to process an ASCII file
|
31
|
-
file_type = 'ASCII'
|
32
37
|
format = 'EXTENDED'
|
33
|
-
@ascii_data = echi_handler.process_file(ascii_file,
|
38
|
+
@ascii_data = echi_handler.process_file(ascii_file, format, extra_byte)
|
34
39
|
end
|
35
40
|
|
36
41
|
def teardown
|
37
42
|
end
|
38
43
|
|
44
|
+
#Test method that determine filetype
|
45
|
+
def test_filetype_ascii
|
46
|
+
assert_equal("ASCII", @filetype_ascii)
|
47
|
+
end
|
48
|
+
|
49
|
+
#Test method that determine filetype
|
50
|
+
def test_filetype_binary
|
51
|
+
assert_equal("BINARY", @filetype_binary)
|
52
|
+
end
|
53
|
+
|
39
54
|
#Test that processing a binary file works
|
40
55
|
def test_binary_file
|
41
56
|
assert_equal(@proper_unstripped, @binary_data)
|
@@ -50,4 +65,5 @@ class EchiFiles_Test < Test::Unit::TestCase
|
|
50
65
|
def test_ascii_file
|
51
66
|
assert_equal(@ascii_data, @proper_ascii)
|
52
67
|
end
|
68
|
+
|
53
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsgoecke-echi_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Goecke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-26 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|