Sha256: fb261ead2780bc033847a5e2267711c9bbdd5ad3f15327daf849c986f673a281

Contents?: true

Size: 804 Bytes

Versions: 3

Compression:

Stored size: 804 Bytes

Contents

require 'komic/builder/pdf'
require 'komic/builder/douban_album'
require 'uri'

module Komic::Builder
  class Factory
    class << self
      def detect_type(string)
        path = File.join(Dir.pwd, string)
        r_douban_album = Regexp.new "www.douban.com/photos/album/"

        if string =~ URI::regexp and string =~ r_douban_album
          return 'douban_album'
        end

        if File.exists?(path)
          if File.extname(path) == '.pdf'
            return 'pdf'
          end
        end
        raise "Builder can't be found."
      end

      def get_builder(type_string, options)
        case detect_type(type_string)
        when 'pdf' then PDF.new(type_string, options)
        when 'douban_album' then DoubanAlbum.new(type_string, options)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
komic-cli-0.1.5 lib/komic/builder.rb
komic-cli-0.1.4 lib/komic/builder.rb
komic-cli-0.1.3 lib/komic/builder.rb