lib/qipowl/core/bowler.rb in qipowl-0.9.0 vs lib/qipowl/core/bowler.rb in qipowl-0.9.1

- old
+ new

@@ -44,11 +44,11 @@ end # Everything is a DSL, remember? # # @return true - def respond_to?(method) + def respond_to? method, incl_priv = false true end # Everything is a DSL, remember? Even constants. # @todo This fails to do with DSLing words, beginning with capitals :-( @@ -66,11 +66,11 @@ def method_missing method, *args, &block method, *args = special_handler(method, *args, &block) \ if self.private_methods.include?(:special_handler) [method, args].flatten end - + # Adds new +entity+ in the section specified. # E. g., call to # # add_spice :linewide, :°, :deg, :degrees # @@ -123,34 +123,34 @@ protected %w(block alone magnet grip regular).each { |section| define_method "∀_#{section}".to_sym, ->(*args) { raise "Default method for #{section} (“#{self.class.name.gsub(/_\d+\Z/, '')}#∀_#{section}”) MUST be defined" - } + } unless Bowler.instance_methods(true).include?("∀_#{section}".to_sym) } def defreeze str str end def roast str - (split str).reverse.map { |dish| + (split str).map { |dish| @yielded = [] rest = begin - eval(dish.strip.carriage) + eval(dish.bowl.carriage) rescue Exception => e msg = e.message.dup logger.error '='*78 - logger.error "Could not roast dish [#{msg.force_encoding(Encoding::UTF_8)}].\nWill return as is… Dish follows:" + logger.error "Could not roast dish [#{msg.force_encoding(Encoding::UTF_8)}].\nWill return as is… Dish follows:\n\n" logger.error '-'*78 logger.error dish logger.error '='*78 [*dish] end harvest(nil, orphan([*rest].join(SEPARATOR))) # FIXME Check if this is correct in all the cases @yielded.pop(@yielded.size).reverse.join(SEPARATOR) - }.reverse.join($/).uncarriage.un␚ify.unspacefy.unbowl + }.join($/).uncarriage.un␚ify.unspacefy.unbowl end def serveup str str.gsub(/⌦./, '').gsub(/.⌫/, '') end @@ -202,48 +202,52 @@ end private # Prepares blocks in the input for the execution def block str + return str unless self.class.const_defined?(:BLOCK_TAGS) result = str.dup self.class::BLOCK_TAGS.each { |tag, value| - result.gsub!(/(#{tag})\s*(\S*\s*|$)(.*?)(#{tag}|\Z)/m) { + result.gsub!(/(#{tag})\s*(\S*\s?|$)(.*?)(#{tag}|\Z)/m) { %Q{ -#{$1}('#{$2.strip}', '#{$3.carriage}') +#{$1} #{$2.strip.bowl} #{$3.bowl.carriage} } } } result end # Prepares customs in the input for the execution def custom str - result = str.unbowl.dup + return str unless self.class.const_defined?(:CUSTOM_TAGS) + result = str.dup self.class::CUSTOM_TAGS.each { |tag, value| - result.gsub!(/#{tag}/, value) + result.gsub!(/#{tag}/m, value) } - result.bowl + result end # Prepares grips in the input for the execution # FIX<E There is a problem: we append a trailing space, need to remove it later!! def grip str - result = str.dup + return str unless self.class.const_defined?(:GRIP_TAGS) + result = str.bowl self.class::GRIP_TAGS.each { |tag, value| result.gsub!(/(?:#{tag})(.*?)(?:#{tag})/m) { next if (args = $1).vacant? tag = value[:marker] if Hash === value && value[:marker] "⌦ #{tag} #{args}#{tag}∎⌫" } } - result + result.unbowl end def split str - (block str.bowl).split(/\R{2,}/).map { |para| - para =~ /\A(#{self.class::BLOCK_TAGS.keys.join('|')})\(/ ? + (block str).split(/\R{2,}/).map { |para| + self.class.const_defined?(:BLOCK_TAGS) && + (para =~ /\A(#{self.class::BLOCK_TAGS.keys.join('|')})\s+/) ? para : (grip custom para) } end end