Module: Katte::Plugins::FileType
- Extended by:
- Base
- Defined in:
- lib/katte/plugins/file_type.rb
Defined Under Namespace
Classes: Bash, Debug, Hive, R, Rubyn
Instance Method Summary collapse
Methods included from Base
define_keyword, find, included, index, plugins, register
Instance Method Details
#convert_variable(value) ⇒ Object
43 44 45 46 |
# File 'lib/katte/plugins/file_type.rb', line 43 def convert_variable(value) # #{xx} というパターンを env['xx'] で置換する value.gsub(/\#\{((?:\\\{|[^\{])+)\}/) {|m| Katte.app.env.to_hash[$1]} end |
#parse(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/katte/plugins/file_type.rb', line 15 def parse(path) c = Regexp.escape(comment_by) @comment_pattern ||= /^#{c}|^\s*$/ @directive_pattern ||= %r{ ^#{c}\s* # comment (?<key>\w+)\s*:\s* # key (?<value>[^(\s]+) # value (\((?<params>[^)]*)\))? # param (optional) $ }x directive = Hash.new {|h,k| h[k] = [] } open(path) do |io| while line = io.gets line.chomp! break unless @comment_pattern.match(line) next unless m = @directive_pattern.match(line) key = m[:key] value = m[:value].strip params = m[:params] && m[:params].split(',').map(&:strip).map(&method(:convert_variable)) directive[key] << [value, params] end end directive end |