Class: DCA::Models::NokogiriBinder
- Inherits:
-
Object
- Object
- DCA::Models::NokogiriBinder
- Includes:
- BinderHelper
- Defined in:
- lib/dca/models/nokogiri_binder.rb
Class Method Summary collapse
- .parse(object, content, params) ⇒ Object
- .parse_many(object, content, params) ⇒ Object
- .parse_one(object, content, params) ⇒ Object
Class Method Details
.parse(object, content, params) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/dca/models/nokogiri_binder.rb', line 6 def self.parse object, content, params if params[:association] == :one parse_one object, content, params elsif params[:association] == :many parse_many object, content, params end end |
.parse_many(object, content, params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dca/models/nokogiri_binder.rb', line 28 def self.parse_many object, content, params result = nil = params[:options] || {} selector = [:selector] type = params[:type] type = find_type object, params[:field], [:polymorphic] if type.nil? || [:polymorphic] unless selector.nil? result = content.css(selector) result = object.send([:parser], result) unless [:parser].nil? result = result.map { |node| type.new.bind node } unless result.nil? end result end |
.parse_one(object, content, params) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dca/models/nokogiri_binder.rb', line 14 def self.parse_one object, content, params result = nil = params[:options] || {} selector = [:selector] element = selector.nil? ? content : content.at_css(selector) unless element.nil? result = [:attribute].nil? ? element.content : element[[:attribute]] end result = self. object, result, convert result, params[:type] end |