Sha256: aa12f5521ec2e4b015eec3670718554a138fcc3b06f406b42d7ed1e62f1e5a86

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8
module Nokaya

  class Basic

    attr_reader :options, :args, :filenames, :type, :name, :path
    attr_accessor :urls

    def initialize args, options
      Logs.create_logger
      @options = options
      @workers = Workers.new(options)
      @args = args
      @filenames = []
      @urls = []
      @path = @workers.path
      @type = :basic
      @name = options['name'] if options['name']
      @platform = RbConfig::CONFIG['host_os']
    end

    def get_basic page
      page.xpath("//meta[@property='og:image']/@content").first.value unless page.nil?
    end

    def parse url
      begin
        Nokogiri::HTML(open url)
      rescue Errno::ENOENT => e
        Logs.rec.error e
        puts Status.no_url if options['verbose']
        return nil
      rescue OpenURI::HTTPError => e
        Logs.rec.error e
        puts Status.no_can_do if options['verbose']
        return nil
      rescue Exception => e
        Logs.rec.error e
        puts Status.error if options['verbose']
        return nil
      end
    end

    def save
      @workers.save(self)
    end

    def name_files
      @urls.map do |url|
        "#{@type.to_s}-#{@author}-#{File.basename(url)}"
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nokaya-0.1.6 lib/nokaya/basic.rb
nokaya-0.1.5 lib/nokaya/basic.rb
nokaya-0.1.4 lib/nokaya/basic.rb
nokaya-0.1.3 lib/nokaya/basic.rb