fixedfixer 0.1.0
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.
- data/License +20 -0
- data/Manifest +5 -0
- data/README.rdoc +25 -0
- data/Rakefile +15 -0
- data/fixedfixer.gemspec +29 -0
- data/lib/fixedfixer.rb +36 -0
- metadata +67 -0
data/License
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Matt Mondok
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= About
|
2
|
+
|
3
|
+
FixedFixer takes either a fixed-length file or a fixed-length array of strings and parses it based on given lengths.
|
4
|
+
|
5
|
+
Author:: Matt Mondok
|
6
|
+
Date:: 03/05/2011
|
7
|
+
Homepage:: http://wwww.sprocketlauncher.com
|
8
|
+
Copyright:: 2011 Matt Mondok
|
9
|
+
|
10
|
+
== Examples
|
11
|
+
|
12
|
+
=== Parsing a file
|
13
|
+
# fixed_length_file.txt contains lines:
|
14
|
+
# thiscarison
|
15
|
+
# helptheisof
|
16
|
+
|
17
|
+
require 'fixedfixer'
|
18
|
+
|
19
|
+
FixedFixer.parse("fixed_length_file.txt", [4,3,2,2])
|
20
|
+
# returns [["this", "car", "is", "on"], ["help", "the", "is", "of"]]
|
21
|
+
|
22
|
+
=== Parsing an array
|
23
|
+
require 'fixedfixer'
|
24
|
+
FixedFixer.parse(["thiscarison","helptheisof"],[4,3,2,2])
|
25
|
+
# returns [["this", "car", "is", "on"], ["help", "the", "is", "of"]]
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Rakefile
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
Echoe.new('fixedfixer', '0.1.0') do |p|
|
7
|
+
p.description = "Parses fixed length files into arrays"
|
8
|
+
p.url = "http://github.com/mondok/fixedfixer"
|
9
|
+
p.author = "Matt Mondok"
|
10
|
+
p.email = "matt.mondok@gmail.com"
|
11
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
12
|
+
p.development_dependencies = []
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/fixedfixer.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{fixedfixer}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Matt Mondok"]
|
9
|
+
s.date = %q{2011-03-06}
|
10
|
+
s.description = %q{Parses fixed length files into arrays}
|
11
|
+
s.email = %q{matt.mondok@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/fixedfixer.rb"]
|
13
|
+
s.files = ["License", "README.rdoc", "Rakefile", "lib/fixedfixer.rb", "Manifest", "fixedfixer.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/mondok/fixedfixer}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fixedfixer", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{fixedfixer}
|
18
|
+
s.rubygems_version = %q{1.6.1}
|
19
|
+
s.summary = %q{Parses fixed length files into arrays}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
data/lib/fixedfixer.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module FixedFixer
|
2
|
+
# def self.included(base)
|
3
|
+
# base.extend ClassMethods
|
4
|
+
# end
|
5
|
+
|
6
|
+
# module ClassMethods
|
7
|
+
def self.parse(input, lengths)
|
8
|
+
format = "a" << lengths.join("a")
|
9
|
+
if input.is_a? Array
|
10
|
+
parse_array(input, format)
|
11
|
+
else
|
12
|
+
parse_file(input, format)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def self.parse_array(data, format)
|
18
|
+
result = []
|
19
|
+
data.each do |d|
|
20
|
+
result << d.unpack(format)
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_file(file_path, format)
|
26
|
+
result = []
|
27
|
+
File.open(file_path, "r") do |f|
|
28
|
+
while (line = f.gets)
|
29
|
+
result << line.unpack(format)
|
30
|
+
end
|
31
|
+
f.close
|
32
|
+
end
|
33
|
+
result
|
34
|
+
# end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fixedfixer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Mondok
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-06 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Parses fixed length files into arrays
|
18
|
+
email: matt.mondok@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
- lib/fixedfixer.rb
|
26
|
+
files:
|
27
|
+
- License
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- lib/fixedfixer.rb
|
31
|
+
- Manifest
|
32
|
+
- fixedfixer.gemspec
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/mondok/fixedfixer
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --line-numbers
|
40
|
+
- --inline-source
|
41
|
+
- --title
|
42
|
+
- Fixedfixer
|
43
|
+
- --main
|
44
|
+
- README.rdoc
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "1.2"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project: fixedfixer
|
62
|
+
rubygems_version: 1.6.1
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Parses fixed length files into arrays
|
66
|
+
test_files: []
|
67
|
+
|