Html2record
This gem provide a simple way that bind html specific element to a record column
Installation
In Gemfile add follow line:
gem 'html2record'Get Start
init parser file
rails g parser Taobao
this command will generate a parser into folder app/parsers/
class TaobaoParser < Html2record::Parser::Base
endyou can add column binding in class
class TaobaoParser < Html2record::Parser::Base
add :title, '#main .title'
endIn model file include the class
include Html2record::ActiveRecordUse the model:
html =<<-page
<html>
<body>
<div id="main">
<div><span class="title">hello</span></div>
<div><span class="content">world</span></div>
</div>
<body>
</html>
page
good = Good.new
good.apply_html(Taobao,html) # good.title should be 'hello'This project rocks and uses MIT-LICENSE.