forked from ornlabs/sinatrademo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcakes.rb
28 lines (22 loc) · 925 Bytes
/
cakes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'nokogiri'
require 'open-uri'
require 'data_mapper'
require 'dm-migrations'
DataMapper.setup(:default, 'sqlite:///tmp/test.db')
class Cake
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :name, String # A varchar type string, for short strings
property :imageURL, String, :length => 1024 # The URL to the image
property :description, String, :length => 1024 # The description of the cake
end
DataMapper.finalize
DataMapper.auto_migrate!
doc = Nokogiri::HTML(open('cakesFull.html'))
doc.css('table.wikitable tr').each do |element|
temp = element.css('td')
next if temp[0].nil?
next if temp[1].css('img').length == 0
next if temp[3].nil?
Cake.create(:name => temp[0].content, :imageURL => "http:" + temp[1].css('img')[0].attributes['src'], :description => temp[3].content)
end