class DWML::HeadExtractor
Attributes
element[R]
output[R]
Public Class Methods
new(element)
click to toggle source
# File lib/dwml/head_extractor.rb, line 5 def initialize(element) @element = element @output = {} end
Public Instance Methods
process()
click to toggle source
# File lib/dwml/head_extractor.rb, line 10 def process build_product build_source output end
Protected Instance Methods
build_product()
click to toggle source
# File lib/dwml/head_extractor.rb, line 18 def build_product creation_date = Time.zone.parse(element.xpath('product/creation-date').text) @output.merge!( :product => { :title => normalize_content( 'product/title' ), :field => normalize_content( 'product/field' ), :category => normalize_content( 'product/category' ), :creation_date => creation_date } ) end
build_source()
click to toggle source
# File lib/dwml/head_extractor.rb, line 31 def build_source sub_center = element.xpath('source/production-center/sub-center').text production_center = element.xpath('source/production-center').text @output.merge!( :source => { :product_center => production_center.gsub(sub_center, " - #{sub_center}"), :more_information => normalize_content( 'source/more-information' ), :disclaimer => normalize_content( 'source/disclaimer' ), :credit => normalize_content( 'source/credit' ), :credit_logo => normalize_content( 'source/credit-logo' ), :feedback => normalize_content( 'source/feedback' ) } ) end
normalize_content(selector)
click to toggle source
# File lib/dwml/head_extractor.rb, line 47 def normalize_content(selector) node = element.xpath(selector) if node.blank? "" else node.text end end