estratto 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 85163d2c0a538051b28455d2181c17cd6ae837f8
4
- data.tar.gz: fc2acd57033f720cef6678e11f83f4b29b3f6092
2
+ SHA256:
3
+ metadata.gz: 81ad6d5b175ef7ddbbf1d8e279715585e39c39e29fb930f710700d1d41075460
4
+ data.tar.gz: 35e2d119781e972cc45116224969681b95f801d3e32afca5b61d865ac824bce4
5
5
  SHA512:
6
- metadata.gz: d5aeeaf6c9f6f55b1cd3e511e10b02c1c0b905493c8606eb5823e3729294b630f894ae9ffa96ee4922f1e6b99ca9b7a927d7ab2156e3655e4669d9caef563212
7
- data.tar.gz: 76aa93b70e90e2a16c1b8c50246fbeaff2ad4a01af53e7136dea9d1521e1163f2906c08142fc4ad88b8263652abd9a9eb4c434bf9f74df297378b8493347d119
6
+ metadata.gz: b9fff31ab9057250a0bef1d96c25ac8d60e1e5fa37cbf7a175554114751058807e3aac524e397c578f88279b96434335f2386f14570dd1021e1eed57f20c8252
7
+ data.tar.gz: eeef2f8df3fc33cc053fa59cad2e752924d1ca26584b25a35e9efafc491820a4348f51738e6353b8f3bed69093d6342319e239029510132693ffdbb3a0eab8cd
@@ -0,0 +1,3 @@
1
+ ### 1.0.3 (05/09/20189)
2
+
3
+ * Implement coercer error improvement, that expose data, and line number that raises error
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 TODO: Write your name
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
  [![Coverage Status](https://coveralls.io/repos/github/Rynaro/estratto/badge.svg?branch=master)](https://coveralls.io/github/Rynaro/estratto?branch=master)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/46532b90e850401fce72/maintainability)](https://codeclimate.com/github/Rynaro/estratto/maintainability)
7
7
 
8
- [![Waffle.io - Columns and their card count](https://badge.waffle.io/Rynaro/estratto.svg?columns=all)](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.
@@ -13,7 +13,6 @@ module Estratto
13
13
  def coerce
14
14
  raise TypeCoercionNotFound
15
15
  end
16
-
17
16
  end
18
17
  end
19
18
  end
@@ -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
@@ -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
 
@@ -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 || {}
@@ -1,3 +1,3 @@
1
1
  module Estratto
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
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.2
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-01-30 00:00:00.000000000 Z
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
- rubyforge_project:
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