From: Andrew Wagner Date: 2013-03-09T11:43:31+09:00 Subject: Re: RubyExcel class. Useful? --20cf307d003043065e04d774cd61 Content-Type: text/plain; charset=UTF-8 Thanks. One thing that strikes me, looking through the code, is that Column and Row are very similar. It wouldn't surprise me if you could pull a lot more logic up into the base class. I also have the vague feeling that this could generally be done with a lot less code. But talk is cheap, so take that with a grain of salt. What are you using this for? It's certainly an interesting exercise, if nothing else. On Fri, Mar 8, 2013 at 8:33 PM, Joel Pearson wrote: > Good point Andrew. Writing a thorough demo is a good way to > systematically test every method as well. > I just tried to demo some of the newer stuff I added and I've already > found a couple of bugs where I have class methods referenced rather than > the mix-in methods I changed to recently. I'll run a thorough series of > tests, build up some examples, and then try again. > > This covers some of the basics anyway: > > irb(main):002:0> re = RubyExcel.new.test > => RubyExcel => columns: 4, rows: 6, values: 24 > irb(main):003:0> puts re > a b c d > e f g h > i j k l > m n o p > q r s t > u v w x > => nil > irb(main):004:0> re['B2'] = 'z' > => "z" > irb(main):005:0> re.column_by_header('c').map! { |el| el.next } > => Class: RubyExcel::Column, Index: C > irb(main):006:0> puts re > a b d d > e z h h > i j l l > m n p p > q r t t > u v x x > => nil > irb(main):007:0> re.delete_column('D') > => RubyExcel => columns: 3, rows: 6, values: 18 > irb(main):008:0> re.cell(2,3).value = 'z' > => "z" > irb(main):009:0> puts re > a b d > e z z > i j l > m n p > q r t > u v x > => nil > irb(main):010:0> re += [ %w(1 2 3) ] > => RubyExcel => columns: 3, rows: 7, values: 21 > irb(main):011:0> puts re > a b d > e z z > i j l > m n p > q r t > u v x > 1 2 3 > => nil > irb(main):012:0> re.filter!('b') { |el| el =~ /[a-r]/ } > => RubyExcel => columns: 3, rows: 4, values: 12 > irb(main):013:0> puts re > a b d > i j l > m n p > q r t > => nil > irb(main):014:0> re.row(2)['A'] = 'q' > => "q" > irb(main):015:0> re.summarise 'a' > => {"q"=>2, "m"=>1} > irb(main):016:0> puts re > a b d > q j l > m n p > q r t > => nil > irb(main):017:0> puts re.uniq! 'a' > a b d > q j l > m n p > => nil > > -- > Posted via http://www.ruby-forum.com/. > > --20cf307d003043065e04d774cd61 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks. One thing that strikes me, looking through the cod= e, is that Column and Row are very similar. It wouldn't surprise me if = you could pull a lot more logic up into the base class. I also have the vag= ue feeling that this could generally be done with a lot less code. But talk= is cheap, so take that with a grain of salt. What are you using this for? = It's certainly an interesting exercise, if nothing else.


On Fri, Mar 8, 2013 at 8:33 PM, Joel Pea= rson <lists@ruby-forum.com> wrote:
Good point Andrew. Writing a thorough demo i= s a good way to
systematically test every method as well.
I just tried to demo some of the newer stuff I added and I've already found a couple of bugs where I have class methods referenced rather than the mix-in methods I changed to recently. I'll run a thorough series of=
tests, build up some examples, and then try again.

This covers some of the basics anyway:

irb(main):002:0> re =3D RubyExcel.new.test
=3D> RubyExcel =3D> columns: 4, rows: 6, values: 24
irb(main):003:0> puts re
a =C2=A0 =C2=A0 =C2=A0 b =C2=A0 =C2=A0 =C2=A0 c =C2=A0 =C2=A0 =C2=A0 d
e =C2=A0 =C2=A0 =C2=A0 f =C2=A0 =C2=A0 =C2=A0 g =C2=A0 =C2=A0 =C2=A0 h
i =C2=A0 =C2=A0 =C2=A0 j =C2=A0 =C2=A0 =C2=A0 k =C2=A0 =C2=A0 =C2=A0 l
m =C2=A0 =C2=A0 =C2=A0 n =C2=A0 =C2=A0 =C2=A0 o =C2=A0 =C2=A0 =C2=A0 p
q =C2=A0 =C2=A0 =C2=A0 r =C2=A0 =C2=A0 =C2=A0 s =C2=A0 =C2=A0 =C2=A0 t
u =C2=A0 =C2=A0 =C2=A0 v =C2=A0 =C2=A0 =C2=A0 w =C2=A0 =C2=A0 =C2=A0 x
=3D> nil
irb(main):004:0> re['B2'] =3D 'z'
=3D> "z"
irb(main):005:0> re.column_by_header('c').map! { |el| el.next }<= br> =3D> Class: RubyExcel::Column, Index: C
irb(main):006:0> puts re
a =C2=A0 =C2=A0 =C2=A0 b =C2=A0 =C2=A0 =C2=A0 d =C2=A0 =C2=A0 =C2=A0 d
e =C2=A0 =C2=A0 =C2=A0 z =C2=A0 =C2=A0 =C2=A0 h =C2=A0 =C2=A0 =C2=A0 h
i =C2=A0 =C2=A0 =C2=A0 j =C2=A0 =C2=A0 =C2=A0 l =C2=A0 =C2=A0 =C2=A0 l
m =C2=A0 =C2=A0 =C2=A0 n =C2=A0 =C2=A0 =C2=A0 p =C2=A0 =C2=A0 =C2=A0 p
q =C2=A0 =C2=A0 =C2=A0 r =C2=A0 =C2=A0 =C2=A0 t =C2=A0 =C2=A0 =C2=A0 t
u =C2=A0 =C2=A0 =C2=A0 v =C2=A0 =C2=A0 =C2=A0 x =C2=A0 =C2=A0 =C2=A0 x
=3D> nil
irb(main):007:0> re.delete_column('D')
=3D> RubyExcel =3D> columns: 3, rows: 6, values: 18
irb(main):008:0> re.cell(2,3).value =3D 'z'
=3D> "z"
irb(main):009:0> puts re
a =C2=A0 =C2=A0 =C2=A0 b =C2=A0 =C2=A0 =C2=A0 d
e =C2=A0 =C2=A0 =C2=A0 z =C2=A0 =C2=A0 =C2=A0 z
i =C2=A0 =C2=A0 =C2=A0 j =C2=A0 =C2=A0 =C2=A0 l
m =C2=A0 =C2=A0 =C2=A0 n =C2=A0 =C2=A0 =C2=A0 p
q =C2=A0 =C2=A0 =C2=A0 r =C2=A0 =C2=A0 =C2=A0 t
u =C2=A0 =C2=A0 =C2=A0 v =C2=A0 =C2=A0 =C2=A0 x
=3D> nil
irb(main):010:0> re +=3D [ %w(1 2 3) ]
=3D> RubyExcel =3D> columns: 3, rows: 7, values: 21
irb(main):011:0> puts re
a =C2=A0 =C2=A0 =C2=A0 b =C2=A0 =C2=A0 =C2=A0 d
e =C2=A0 =C2=A0 =C2=A0 z =C2=A0 =C2=A0 =C2=A0 z
i =C2=A0 =C2=A0 =C2=A0 j =C2=A0 =C2=A0 =C2=A0 l
m =C2=A0 =C2=A0 =C2=A0 n =C2=A0 =C2=A0 =C2=A0 p
q =C2=A0 =C2=A0 =C2=A0 r =C2=A0 =C2=A0 =C2=A0 t
u =C2=A0 =C2=A0 =C2=A0 v =C2=A0 =C2=A0 =C2=A0 x
1 =C2=A0 =C2=A0 =C2=A0 2 =C2=A0 =C2=A0 =C2=A0 3
=3D> nil
irb(main):012:0> re.filter!('b') { |el| el =3D~ /[a-r]/ }
=3D> RubyExcel =3D> columns: 3, rows: 4, values: 12
irb(main):013:0> puts re
a =C2=A0 =C2=A0 =C2=A0 b =C2=A0 =C2=A0 =C2=A0 d
i =C2=A0 =C2=A0 =C2=A0 j =C2=A0 =C2=A0 =C2=A0 l
m =C2=A0 =C2=A0 =C2=A0 n =C2=A0 =C2=A0 =C2=A0 p
q =C2=A0 =C2=A0 =C2=A0 r =C2=A0 =C2=A0 =C2=A0 t
=3D> nil
irb(main):014:0> re.row(2)['A'] =3D =C2=A0'q'
=3D> "q"
irb(main):015:0> re.summarise 'a'
=3D> {"q"=3D>2, "m"=3D>1}
irb(main):016:0> puts re
a =C2=A0 =C2=A0 =C2=A0 b =C2=A0 =C2=A0 =C2=A0 d
q =C2=A0 =C2=A0 =C2=A0 j =C2=A0 =C2=A0 =C2=A0 l
m =C2=A0 =C2=A0 =C2=A0 n =C2=A0 =C2=A0 =C2=A0 p
q =C2=A0 =C2=A0 =C2=A0 r =C2=A0 =C2=A0 =C2=A0 t
=3D> nil
irb(main):017:0> puts re.uniq! 'a'
a =C2=A0 =C2=A0 =C2=A0 b =C2=A0 =C2=A0 =C2=A0 d
q =C2=A0 =C2=A0 =C2=A0 j =C2=A0 =C2=A0 =C2=A0 l
m =C2=A0 =C2=A0 =C2=A0 n =C2=A0 =C2=A0 =C2=A0 p
=3D> nil

--20cf307d003043065e04d774cd61--