Sha256: fd2edb81547b66c16743baa4f7b192047be15b1b89158aa6602927eff23de1a7

Contents?: true

Size: 1.88 KB

Versions: 18

Compression:

Stored size: 1.88 KB

Contents

#coding=utf-8

require "pathname"

module Aio::Module
	class InputStyle
		
		class ErrorModuleInput < StandardError
			def to_s; "请重载此方法"; end
		end

		# 重要!
		# 输入文件
		attr_accessor :input_file

		# 信息
		attr_accessor 	:input_info

		# 外加信息,用于针对特殊情况
		attr_accessor :ext_info

		def initialize(info={})
			@input_info = info.dup
			set_defaults()
		end

		def set_defaults
			self.input_info = {
				:author				=> nil,
				:description 	=> "No Input Description",
				# 产生文件的平台
				:platform			=> nil,
				:file_suffix	=> nil,
				:pass_file		=> nil,
				:license   		=> ::Aio::AIO_LICENSE,
			}.update(@input_info)

		end

		def type
			Aio::Module::InputStyle
		end

		# 保证输出的file为Pathname类
		def check_file(file)
			if file.class != Pathname
				case file.class
				when String
					file = Pathname.new(file)
				when File
					file = Pathname.new(file.path)
				end
			end
			file
		end

		# 请重载此方法
		def parse
			raise ErrorModuleInput.new			
		end

		# 检查是否符合文件后缀,符合返回真
		def file_suffix?(file)
			if self.file_suffix.match(file)
				return true
			end
			return false
		end

		# 检查是否符合pass_file, 符合返回真
		def pass_file?(file)
			self.pass_file.each do |pass|
				if pass.match(Aio::Base::Toolkit::String.safe(file))
					return true
				end
			end
			return false
		end

		def input_file
			@input_info[:input_file]
		end

		def input_file=(file)
			file = check_file(file)
			@input_info[:input_file] = file
		end

		def author;    		self.input_info[:author];    		end 
		def description;  self.input_info[:description];  end 
		def platform;  		self.input_info[:platform];  		end 
		def file_suffix;	self.input_info[:file_suffix];	end
		def license;   		self.input_info[:license];   		end 
		def pass_file;		self.input_info[:pass_file];		end


	end	# class
end	# module

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aio_elin-1.1.8 lib/aio/core/module/input_style.rb
aio_elin-1.1.7 lib/aio/core/module/input_style.rb
aio_elin-1.1.4 lib/aio/core/module/input_style.rb
aio_elin-1.1.3 lib/aio/core/module/input_style.rb
aio_elin-1.1.2 lib/aio/core/module/input_style.rb
aio_elin-1.1.1 lib/aio/core/module/input_style.rb
aio_elin-1.1.0 lib/aio/core/module/input_style.rb
aio_elin-1.0.9 lib/aio/core/module/input_style.rb
aio_elin-1.0.8 lib/aio/core/module/input_style.rb
aio_elin-1.0.7 lib/aio/core/module/input_style.rb
aio_elin-1.0.6 lib/aio/core/module/input_style.rb
aio_elin-1.0.5 lib/aio/core/module/input_style.rb
aio_elin-1.0.4 lib/aio/core/module/input_style.rb
aio_elin-1.0.3 lib/aio/core/module/input_style.rb
aio_elin-1.0.2 lib/aio/core/module/input_style.rb
aio_elin-1.0.1 lib/aio/core/module/input_style.rb
aio_elin-1.0.0 lib/aio/core/module/input_style.rb
aio_elin-0.0.1 lib/aio/core/module/input_style.rb