Created
May 3, 2015 13:39
-
-
Save Tux/12387de2febd2eda1efc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CSV::Row is Iterable does Positional { | |
has Text::CSV $.csv; | |
has CSV::Field @.fields is rw; | |
multi method new (@f) { | |
@!fields = @f.map ({ CSV::Field.new (*) }); | |
} | |
method Str { $!csv ?? $!csv.string (@!fields) !! Str; } | |
method iterator { [ @.fields ].iterator; } | |
method hash { my @h = $!csv.column_names or return; | |
hash @h Z @!fields; | |
} | |
method AT-POS (int $i) { @!fields[$i]; } | |
multi method push (CSV::Field $f) { @!fields.push: $f; } | |
multi method push (Cool $f) { @!fields.push: CSV::Field.new ($f); } | |
# multi method push (CSV::Row $r) { for ($r.fields) -> $f { @!fields.push: $f; }} | |
multi method push (CSV::Row $r) { @!fields.push: @$r.fields; }} | |
method pop returns CSV::Field { @!fields.pop; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment