estratto 1.0.2 → 1.0.3
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +1 -1
- data/README.md +16 -2
- data/lib/estratto/data/base.rb +0 -1
- data/lib/estratto/data/coercer.rb +8 -4
- data/lib/estratto/parser.rb +2 -2
- data/lib/estratto/register.rb +4 -2
- data/lib/estratto/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 81ad6d5b175ef7ddbbf1d8e279715585e39c39e29fb930f710700d1d41075460
|
4
|
+
data.tar.gz: 35e2d119781e972cc45116224969681b95f801d3e32afca5b61d865ac824bce4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9fff31ab9057250a0bef1d96c25ac8d60e1e5fa37cbf7a175554114751058807e3aac524e397c578f88279b96434335f2386f14570dd1021e1eed57f20c8252
|
7
|
+
data.tar.gz: eeef2f8df3fc33cc053fa59cad2e752924d1ca26584b25a35e9efafc491820a4348f51738e6353b8f3bed69093d6342319e239029510132693ffdbb3a0eab8cd
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2019
|
3
|
+
Copyright (c) 2019 Henrique Aparecido Lavezzo
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
[](https://coveralls.io/github/Rynaro/estratto?branch=master)
|
6
6
|
[](https://codeclimate.com/github/Rynaro/estratto/maintainability)
|
7
7
|
|
8
|
-
[](https://waffle.io/Rynaro/estratto)
|
9
|
-
|
10
8
|
> Estratto is a easy to handle parser based on YAML templating engine. Creating a easy interface for developers, and non developers to extract data from fixed width files
|
11
9
|
|
12
10
|
## Motivation
|
@@ -102,6 +100,22 @@ Actually **Estratto** supports these types of fixed width layouts:
|
|
102
100
|
Estratto makes use of [CharlockHolmes](https://github.com/brianmario/charlock_holmes) gem to detect the file content encoding and convert it to UTF-8.
|
103
101
|
This approach prevents invalid characters from being present in the output.
|
104
102
|
|
103
|
+
CharlockHolmes uses [ICU](http://site.icu-project.org) for charset detection. And you need libicu in your environment.
|
104
|
+
|
105
|
+
#### Linux
|
106
|
+
|
107
|
+
RedHat, CentOS, Fedora:
|
108
|
+
|
109
|
+
`yum install libicu-devel`
|
110
|
+
|
111
|
+
Debian based:
|
112
|
+
|
113
|
+
`apt-get install libicu-dev`
|
114
|
+
|
115
|
+
#### Homebrew
|
116
|
+
|
117
|
+
`brew install icu4c`
|
118
|
+
|
105
119
|
### Type Coercion
|
106
120
|
|
107
121
|
**Estratto** supports type coercion, with some perks called _formats_, on layout file.
|
data/lib/estratto/data/base.rb
CHANGED
@@ -7,24 +7,28 @@ require_relative 'string'
|
|
7
7
|
module Estratto
|
8
8
|
module Data
|
9
9
|
class InvalidCoercionType < StandardError; end
|
10
|
-
|
10
|
+
class DataCoercionError < StandardError; end
|
11
11
|
class Coercer
|
12
|
-
attr_reader :data, :type, :formats
|
12
|
+
attr_reader :data, :index, :type, :formats
|
13
13
|
|
14
|
-
def initialize(data:, type: 'String', formats: {})
|
14
|
+
def initialize(data:, index:, type: 'String', formats: {})
|
15
15
|
@data = data
|
16
|
+
@index = index
|
16
17
|
@type = type
|
17
18
|
@formats = formats
|
18
19
|
end
|
19
20
|
|
20
21
|
def build
|
21
22
|
target_coercer.coerce
|
23
|
+
rescue StandardError => error
|
24
|
+
raise DataCoercionError,
|
25
|
+
"Error when coercing #{data} on line #{index}, raising: #{error.message}"
|
22
26
|
end
|
23
27
|
|
24
28
|
def target_coercer
|
25
29
|
Object.const_get("Estratto::Data::#{type}").new(data, formats)
|
26
30
|
rescue NameError
|
27
|
-
raise InvalidCoercionType
|
31
|
+
raise InvalidCoercionType, "Does not exists coercer class for #{type}"
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
data/lib/estratto/parser.rb
CHANGED
@@ -11,10 +11,10 @@ module Estratto
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def perform
|
14
|
-
@data ||= raw_content.map do |line|
|
14
|
+
@data ||= raw_content.map.with_index do |line, index|
|
15
15
|
register_layout = layout.register_fields_for(line[layout.prefix_range])
|
16
16
|
next if register_layout.nil?
|
17
|
-
Register.new(line, register_layout).refine
|
17
|
+
Register.new(line, index, register_layout).refine
|
18
18
|
end.compact
|
19
19
|
end
|
20
20
|
|
data/lib/estratto/register.rb
CHANGED
@@ -3,10 +3,11 @@ require_relative 'helpers/range'
|
|
3
3
|
|
4
4
|
module Estratto
|
5
5
|
class Register
|
6
|
-
attr_reader :line, :register_layout
|
6
|
+
attr_reader :line, :index, :register_layout
|
7
7
|
|
8
|
-
def initialize(line, register_layout)
|
8
|
+
def initialize(line, index, register_layout)
|
9
9
|
@line = line
|
10
|
+
@index = index
|
10
11
|
@register_layout = register_layout
|
11
12
|
end
|
12
13
|
|
@@ -22,6 +23,7 @@ module Estratto
|
|
22
23
|
|
23
24
|
def coerced_data(range, type, formats)
|
24
25
|
Estratto::Data::Coercer.new(
|
26
|
+
index: index,
|
25
27
|
data: line[Estratto::Helpers::Range.for(range)],
|
26
28
|
type: type,
|
27
29
|
formats: formats || {}
|
data/lib/estratto/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: estratto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique A. Lavezzo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: charlock_holmes
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
92
|
- ".travis.yml"
|
93
|
+
- CHANGELOG.md
|
93
94
|
- Gemfile
|
94
95
|
- Gemfile.lock
|
95
96
|
- LICENSE.txt
|
@@ -136,8 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
137
|
- !ruby/object:Gem::Version
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
|
-
|
140
|
-
rubygems_version: 2.6.8
|
140
|
+
rubygems_version: 3.0.3
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: Parsing fixed width files made easy
|