Releases: johncarney/pikelet
v2.0.0 Beta 9
- Final README for v2.0.0.
- Added tests for remaining README examples.
- Fixed a bug where processing nil fields would raise an exception.
- Fixed a broken test.
v2.0.0 Release
Adds the following features:
- Custom formatters.
- Alignment and padding options.
- Arbitrarily named signature field.
- Custom record classes
Other changes:
- Removes support for parsing CSV files.
- Fixes a bug whereby fields with custom parsers would not have leading or trailing whitespace stripped.
v2.0.0 Beta 8
- Updated the README for the v2.0.0 release.
- Added tests for most of the README examples.
- Fixed a bug whereby fields with custom parsers would not be stripped.
v2.0.0 Beta 7
- Added
type
option to field definition. This is a shorthand for padding and alignment defaults and can be:alpha
(left-justified, space-padded), or:numeric
(right-justified, zero-padded). - Added
:center
alignment (:centre
is permitted as an alias for the benefit of those of us brought up on British English).
definition = Pikelet.define do
number 0... 3, type: :numeric # Right align the output and pad with zeroes.
name 3...13, align: :center, pad: "." # Centre-align and pad with periods.
end
definition.format([
{ number: 1, name: "Copernicus" },
{ number: 99, name: "Brahe" }
].map(&OpenStruct.method(:new)))
# => [
# "001Copernicus",
# "099..Brahe..."
# ]
v2.0.0 Beta 6
Internal refactoring.
v2.0.0 Beta 5
Moved type_signature
declaration to a signature_field
option on the base definition.
Pikelet.define signature_field: :type do
type 0...4
record "NAME" do
...
end
record "ADDR" do
...
end
end
Previously type_signature
declarations could be made on a per-record basis. This is no longer possible.
The legacy approach of declaring a type_signature
as a field will still work.
Pikelet.define do
type_signature 0...4
record "NAME" do
...
end
record "ADDR" do
...
end
end
v2.0.0 Beta 4
Records can now use custom classes.
class Name
attr_reader :first, :last
def initialize(first: nil, last: nil)
@first = first
@last = last
end
end
Pikelet.define record_class: Name do
first 0...10
last 10...20
end
Here's a slightly more complicated example.
class Name
attr_reader :first, :last
def initialize(**attrs)
@first = attrs[:first]
@last = attrs[:last]
end
end
class Address
attr_reader :street, :city, :postcode, :state, :country
def initialize(**attrs)
@street = attrs[:street]
@city = attrs[:city]
@postcode = attrs[:postcode]
@state = attrs[:state]
@country = attrs[:country]
end
end
Pikelet.define do
type_signature :record_type
record_type 0...4
record "NAME", record_class: Name do
first 4...14
last 14...24
end
record "ADDR", record_class: Address do
street 4...14
city 14...24
postcode 24...29
state 29...39
country 39...49
end
end
v2.0.0 Beta 3
With this release an arbitrary field can be used for the type signature.
Previously type_signature
was defined as a regular field, but treated specially by Pikelet. This meant, among other things, that the records generated always had a type_signature
attribute, which is a bit inelegant. Now you can name your fields however you like and nominate one as the type signature.
Pikelet.define do
type_signature :record_type # Use 'record_type' as the type signature field
record_type 0...4
record "NAME" do
...
end
record "ADDR" do
...
end
end
Note that the type_signature
declaration can precede the declaration of the actual field.
The old type signature syntax (see below) still works, so you do not need to modify any existing definitions.
Pikelet.define do
type_signature 0...4
record "NAME" do
...
end
record "ADDR" do
...
end
end
v2.0.0 Beta 2
In this release we add:
New features
- Custom formatters
- Alignment & padding options
definition = Pikelet.define do
number 0... 3, align: :right, pad: "0" # Right align the output and pad with zeroes.
name 3...13, format: :upcase # Upcase the value on output.
password 13...53, format: ->(v) { Digest::SHA1.hexdigest(v) } # Hash the value.
end
definition.format([
{ number: 1, name: "Copernicus", password: "password" },
{ number: 99, name: "Brahe", password: "sekrit" }
].map(&OpenStruct.method(:new)))
# => [
# "001COPERNICUS5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
# "099BRAHE 8d42e738c7adee551324955458b5e2c0b49ee655"
# ]
Changes
- Alignment defaults to
:left
instead of:right
.
v2.0.0 Beta 1
The next release of Pikelet will be capable of formatting flat-file databases for output. As part of this I will be dropping CSV support as it is constraining my options and, as far as I know, nobody is using it. For the time being I want to let it evolve as a pure flat-file database parser. In a future release I may restore CSV support, but I make no promises.
In this release rudimentary formatting is possible.
Example
definition = Pikelet.define do
type_signature 0...4
record "NAME" do
first_name 4...14
last_name 14...24
end
record "ADDR" do
street_address 4...24
city 24...44
postal_code 44...54
state 54...74
end
end
records = [
{ type_signature: 'NAME', first_name: "Nicolaus", last_name: 'Copernicus' },
{ type_signature: 'ADDR', street_address: "123 South Street", city: "Nowhereville", postal_code: "45678Y", state: "Someplace" }
].map(&OpenStruct.method(:new))
output = definition.format(records)
# => [
# "NAME NicolausCopernicus ",
# "ADDR 123 South Street Nowhereville 45678Y Someplace"
# ]