Sha256: c47871e1597e13eab2b48c3cab06e02ab6293fd660cf6c442d484dd901ebf41a

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

require "oga"
require "httpclient"

require "afr_load/version"
require "afr_load/tv_program"
require "afr_load/parser.rb"

module AfrLoad
    class AfrLoad
        attr_reader :url, :programs, :document

        AFR_LOAD_URL = "http://www.tv-tokyo.co.jp/telecine/oa_afr_load/"

        def initialize(url = AFR_LOAD_URL)
            @programs = Array.new()
            @url = url
        end

        def get_schedule()
            @document = self.class.fetch_schedule(@url)
            @programs = Parser.parse(@document).flatten
            @programs
        end

        def self.get_schedule(url = AFR_LOAD_URL)
            afr = self.new(url)
            afr.get_schedule()
        end

        def self.get_schedule_from_file(file_path)
            handler = File.open(file_path)
            document = Oga.parse_html(handler)
        end

        def self.fetch_schedule(url = AFR_LOAD_URL)
            Oga.parse_html(Enumerator.new do |yielder|
                HTTPClient.get(url) do |chunk|
                    yielder << chunk.force_encoding("utf-8")
                end
            end)
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
afr_load-0.1.1 lib/afr_load.rb