On Mon, Feb 18, 2013 at 6:23 PM, Joel Pearson <[email protected]> wrote:
> That Regexp to proc idea looks good. I could use proc form for a
> positive match and a normal block for the negative. I'll see if I can
> get something like this working when I write filter method for
> RubyExcel.
>
> Using the new class I can implement something like skip_headers by
> passing a starting value to "rows" or "columns". This makes it more
> flexible as well. I've rewritten those iterators using optional start
> and end points:

Actually the even more general concept is filter anything: one might
not only want to skip headers but general rows or columns.

> def rows( start_row = 1, end_row = maxrow )
>   fail TypeError, 'Data is empty' if maxrow == 0
>   fail ArgumentError, 'The starting row must be less than the maximum
> row' if maxrow < start_row
>   return to_enum(:rows) unless block_given?

You need to pass arguments start_row and end_row here as well!

return to_enum(:rows, start_row, end_row) unless block_given?

>   ( start_row..end_row ).each do |idx|
>     yield row( idx )
>   end
>   self
> end
>
> Now I can use rows(2) to skip the headers if necessary. It might be a
> bit confusing when rows(1) actually returns from 1 to the end, but I've
> already got row(1) for that purpose and it makes it shorter to iterate
> through all of them. Plus it means I can do "rows.count", which is the
> same as VBA syntax.
>
> I vaguely understand the idea of passing something in to compare to a
> header type. I'm not sure how I'd implement it though, since the only
> headers I ever deal with are row 1, and they tend to look pretty similar
> to the data itself.

Well, then we should probably add a method #index to Row and Column
which returns the numeric index.  That makes checking whether it's the
n'th row / column easy.  Basically for one of the two the method is
just an alias (not if there is a base 0 or based 1 difference though).

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to