Sha256: 0e6c4cb264c1c99354a1026a9143be9b41615b5e26beb4632ddcbcaf8f079211

Contents?: true

Size: 900 Bytes

Versions: 3

Compression:

Stored size: 900 Bytes

Contents

module Html2rss
  module ItemExtractor
    TEXT = proc { |xml, options|
      element(xml, options)&.text&.strip&.split&.join(' ')
    }

    ATTRIBUTE = proc { |xml, options|
      element(xml, options).attr(options['attribute']).to_s
    }

    HREF = proc { |xml, options|
      href = element(xml, options).attr('href').to_s
      path, query = href.split('?')

      if href.start_with?('http')
        uri = URI(href)
      else
        uri = URI(options['channel']['url'])
        uri.path = path.to_s.start_with?('/') ? path : "/#{path}"
        uri.query = query
      end

      uri
    }

    HTML = proc { |xml, options|
      element(xml, options).to_s
    }

    STATIC = proc { |_xml, options| options['static'] }
    CURRENT_TIME = proc { |_xml, _options| Time.new }

    def self.element(xml, options)
      options['selector'] ? xml.css(options['selector']) : xml
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
html2rss-0.3.3 lib/html2rss/item_extractor.rb
html2rss-0.3.2 lib/html2rss/item_extractor.rb
html2rss-0.3.1 lib/html2rss/item_extractor.rb