Sha256: 708a3dda8de8f0669d10f75ae91ed502ed75a13ede195ca2084dbdc497bd05ae

Contents?: true

Size: 955 Bytes

Versions: 2

Compression:

Stored size: 955 Bytes

Contents

require 'uri'
require 'rss'
require 'time'

module EndiFeed
  # This module contains various useful functions.
  module Util
    def self.included(base)
      base.extend self
    end

    module_function

    # Fetches and parses RSS feed
    # @return [RSS] parsed XML feed or nil
    def parse_feed
      open('http://www.elnuevodia.com/rss/noticias.xml') do |rss|
        RSS::Parser.parse(rss)
      end
    end

    # Converts HTTP-date (RFC 2616) into a simpler date format
    # @param date [Date, String] only Date or String
    # @return [String] parsed date (mm/dd/yyyy)
    def convert_date(date)
      date = String(date)
      Time.parse(date).strftime('%x')
    end

    # Converts HTTP-date (RFC 2616) into the 12-hour format
    # @param date [Date, String] only Date or String
    # @return [String] parsed time (HH:MM:SS AM|PM)
    def convert_time(date)
      date = String(date)
      Time.parse(date).strftime('%r')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
endi_feed-0.0.2 lib/endi_feed/util.rb
endi_feed-0.0.1 lib/endi_feed/util.rb