README.md in excel-esv-0.0.3 vs README.md in excel-esv-0.0.4
- old
+ new
@@ -9,52 +9,58 @@
## Usage
### Generate
-```
+``` ruby
+require "esv"
+
data = ESV.generate do |esv|
esv << [ "Name", "Dogs", "Cats" ]
esv << [ "Victor", 1, 4 ]
end
File.write("/tmp/test.xls", data)
```
### Parse
-```
-excel = File.read("/tmp/test.xls")
+``` ruby
+require "esv"
+
+data = File.read("/tmp/test.xls")
output = ESV.parse(data) # => [ [ "Name", "Dogs", … ], … ]
```
+This assumes a file with a single worksheet and will raise otherwise.
+
### Generate in Ruby on Rails
In `config/initializers/mime_types.rb`:
-```
+``` ruby
Mime::Type.register ESV::MIME_TYPE, "xls"
```
As a model or whatever you prefer:
-```
+``` ruby
class MyExcelDocument
- def generate(name)
+ def self.generate(name)
ESV.generate { |esv| esv << [ "Hello #{name}" ] }
end
end
```
Controller:
-```
+``` ruby
class MyController < ApplicationController
include ESV::RailsController # for send_excel
def show
- data = MyExcelDocument.new("Rails").generate
+ data = MyExcelDocument.generate("Rails")
send_excel(data)
end
def another_example
respond_to do |format|
@@ -68,10 +74,10 @@
## Installation
Add this line to your application's Gemfile:
-```ruby
+``` ruby
gem 'excel-esv'
```
And then execute: