From: Robert Klemme Date: 2013-03-11T03:15:20+09:00 Subject: Re: RubyExcel class. Useful? --047d7b6dc3ac706bd404d79609b7 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Mar 9, 2013 at 10:05 PM, Joel Pearson wrote: > Wow! Lots of good advice, as usual :) It'll take me a while to process > all this so I'll just get on with it. I have attached the skeleton of a class for spreadsheet storage to illustrate what I was saying earlier. Note for example that this class does not have textual cell indexes. I thought it might be easier to use int ranges when focusing on the basic manipulations which will move cells. Depending on storage chosen that may be tricky enough already. A next step could be to create a subclass which allows for CellReferences to register with the class and have them automatically update on successful move operations. I do not know whether you need that but when trying to recreate a spreadsheet application in Ruby that might be an interesting feature to have. As step towards the user your spreadsheet class could wrap the storage class and translate indexes back and forth so the user of your class would only see addresses like "A4" instead of [0, 3]. > Incidentally, I hadn't seen this before: > http://ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV/Table.html > It looks similar in many ways to what I'm trying to build. I'll have to > see what I can learn from it as well. Yes, but keep in mind that CSV has a different mental model: in CSV a row is typically a record, so all the data in a row belongs together. In a spread sheet both dimensions are much more equal. With CSV you won't do operations like inserting a rectangular area somewhere in between while that could be quite common with spread sheets. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --047d7b6dc3ac706bd404d79609b7 Content-Type: application/octet-stream; name="spread-store.rb" Content-Disposition: attachment; filename="spread-store.rb" Content-Transfer-Encoding: base64 X-Attachment-Id: f_he4ij08i0 CiMgQSBzcHJlYWRzaGVldCBzdG9yYWdlIGNsYXNzIHdoaWNoIGlzIHJlc3BvbnNpYmxlIGZvciBi YXNpYwojIG1hbmlwdWxhdGlvbiBvZiB0aGUgYXJlYS4gIHJvdyBhbmQgY29sIGluZGV4ZXMgYXJl IGdpdmVuIGFzCiMgemVybyBiYXNlZCBpbnRlZ2Vycy4gIFZhbHVlcyBjYW4gYmUgYW55dGhpbmcu CmNsYXNzIFNwcmVhZFN0b3JlCgogICMgbWV0aG9kcyB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