Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added YAML support #5

Merged
merged 1 commit into from
Mar 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/remote_table/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def format
Format::HTML
when /xml/
Format::XML
when /yaml/, /yml/
Format::Yaml
else
Format::Delimited
end
Expand Down
1 change: 1 addition & 0 deletions lib/remote_table/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'remote_table/format/fixed_width'
require 'remote_table/format/html'
require 'remote_table/format/xml'
require 'remote_table/format/yaml'
class RemoteTable
class Format

Expand Down
14 changes: 14 additions & 0 deletions lib/remote_table/format/yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'yaml'

class RemoteTable
class Format
class Yaml < Format
def each(&blk)
data = YAML.load_file t.local_file.path
data.each &blk
ensure
t.local_file.cleanup
end
end
end
end
4 changes: 4 additions & 0 deletions test/fixtures/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Seamus Abshere
city: Madison
- name: Derek Kastner
city: Lansing
8 changes: 8 additions & 0 deletions test/test_remote_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class TestRemoteTable < Test::Unit::TestCase
assert_equal 'name', t[0]['col2']
assert_equal 'Seamus Abshere', t[1]['col2']
end

should "open a yaml" do
t = RemoteTable.new "file://#{File.expand_path('../fixtures/data.yml', __FILE__)}"
assert_equal 'Seamus Abshere', t[0]['name']
assert_equal 'Madison', t[0]['city']
assert_equal 'Derek Kastner', t[1]['name']
assert_equal 'Lansing', t[1]['city']
end

should "return an ordered hash" do
t = RemoteTable.new 'http://spreadsheets.google.com/pub?key=tObVAGyqOkCBtGid0tJUZrw'
Expand Down