Hi Sean,

On 05 May 2013, at 07:12, "Sean P. DeNigris" <s...@clipperadams.com> wrote:

>       | reader |
>       FileStream fileNamed: fileName do: [ :file |
>               "skip headers"
>               file
>                       nextLine;
>                       nextLine;
>                       nextLine.
>               reader := NeoCSVReader on: file.
>               reader
>                       separator: Character tab;
>                       recordClass: MyClass;
>                       addField: #name:; "throw away"
>                       addField: #name:;
>                       addField: #type:; "throw away"
>                       addField: #type:; "throw away"
>                       addField: #type: converter: [ :str | MyOtherClass on: 
> str ];
>                       addFloatField: #balance:;
>                       addField: #ignore:;
>                       addField: #ignore:;
>                       addField: #ignore:;
>                       addField: #ignore:.
>               ^ reader upToEnd.
>                ].
> 
> To ignore fields, I'm passing a selector that will be overwritten later on
> in the parsing, but that doesn't work with the last fields, so I had to add
> a special setter to my domain object to ignore those - yuck!
> 
> Is there a feature like this built into NeoCSV?
> 
> Thanks :)

No, but even though it is Sunday, I added it ;-)

You could already have used #next on the NeoCSVReader instead of #nextLine on 
the stream, but I added #skipHeader as an alias.

You should now be able to do this:

        | reader |
        FileStream fileNamed: fileName do: [ :file |
                reader := NeoCSVReader on: file.
                reader
                        separator: Character tab;
                        skipHeader;
                        skipHeader;
                        skipHeader;
                        recordClass: MyClass;
                        addIgnoredField;
                        addField: #name:;
                        addIgnoredField;
                        addIgnoredField;
                        addField: #type: converter: [ :str | MyOtherClass on: 
str ];
                        addFloatField: #balance:;
                        addIgnoredField;
                        addIgnoredField;
                        addIgnoredField;
                        addIgnoredField;
                ^ reader upToEnd ].

Sven

----
Name: Neo-CSV-Core-SvenVanCaekenberghe.13
Author: SvenVanCaekenberghe
Time: 5 May 2013, 2:57:49.884797 pm
UUID: ffa124e8-243a-4eeb-9cfe-9ab553a27ae3
Ancestors: Neo-CSV-Core-SvenVanCaekenberghe.12

Added support for #addIgnoredField as requested by Sean DeNigris;
Added #skipHeader as an alias for #next;
Refactored #readNextRecordAsArray;
Added more method comments
----
Name: Neo-CSV-Tests-SvenVanCaekenberghe.12
Author: SvenVanCaekenberghe
Time: 5 May 2013, 2:59:34.964878 pm
UUID: 0faf0228-3e8f-4b09-b722-c2bae630b36e
Ancestors: Neo-CSV-Tests-SvenVanCaekenberghe.11

Now using #skipHeader;
Added #testReadTestsObjectsWithIgnoredField and #testReadWithIgnoredField
---
Name: ConfigurationOfNeoCSV-SvenVanCaekenberghe.9
Author: SvenVanCaekenberghe
Time: 5 May 2013, 3:01:27.956174 pm
UUID: 7954e3e4-e9cc-485e-9012-9102be0d2fcb
Ancestors: ConfigurationOfNeoCSV-SvenVanCaekenberghe.8

Updated to v7 (ignoreable fields)
----

--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org





Reply via email to