sourcerer 0.5.0.pre.beta → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/examples/simple_test.rb +29 -0
- data/lib/sourcerer.rb +6 -3
- data/lib/sourcerer/cache.rb +13 -0
- data/lib/sourcerer/file.rb +6 -2
- data/lib/sourcerer/helpers.rb +44 -0
- data/lib/sourcerer/method.rb +2 -56
- data/lib/sourcerer/proc.rb +3 -34
- data/lib/sourcerer/proc_source.rb +1 -2
- data/lib/sourcerer/proc_source_body.rb +1 -1
- data/lib/sourcerer/source_code.rb +53 -0
- metadata +8 -5
- data/lib/sourcerer/string.rb +0 -25
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            !binary "U0hBMQ==":
         | 
| 3 3 | 
             
              metadata.gz: !binary |-
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                YjI0ODg5YWM2NzMwODFiNmY5MDAwYTEzYWJjMGQyNjg4YTQ2N2Q0Ng==
         | 
| 5 5 | 
             
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                 | 
| 6 | 
            +
                YzQ3Mzk4YzVhMTMwYTVmZjI2NzExYTk1YWRmZWRkODA4NDhkZjg5OA==
         | 
| 7 7 | 
             
            SHA512:
         | 
| 8 8 | 
             
              metadata.gz: !binary |-
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 9 | 
            +
                ZDQwYTkwMzI2MThjYzEzMjIwODcwZDNjMmVjZTNmNDUzNjFiNTVjMmE3NDBk
         | 
| 10 | 
            +
                NzQ4N2Q0MGZjMDcxYzE0NjBhNzZjYTE4NTM5NzdiOTc3MTgyZjJiMTZmN2Y2
         | 
| 11 | 
            +
                NmUyZTBkYmY4MjRkNDc1ZThjZDIzNmUxNjVmOWUzMjg1MDUyZmI=
         | 
| 12 12 | 
             
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
                 | 
| 15 | 
            -
                 | 
| 13 | 
            +
                YzI4M2ZlOWZhM2FlM2QzNWIzNmM0YTI2MDZiMDllZDUzNGFmOTEwYjQ4MGQ2
         | 
| 14 | 
            +
                NmU1NTg2MGQwNGI1MDYzNDQ5Y2I4OGYxOWU0NTkzZjNiNTAyNjMxNGMyNzlj
         | 
| 15 | 
            +
                MzYxN2VjMTU1MTQ1NjQxZGFhYTU1ZWRkYjczNDBkYThhMWU5MTM=
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.5. | 
| 1 | 
            +
            0.5.1
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            require_relative "../lib/sourcerer.rb"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            test= Proc.new do |sym,options={},*params,&block|
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              puts "some awsome code here"  # comment
         | 
| 6 | 
            +
              puts "yo"
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            end # Proc
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            #puts method(:hello_this).source
         | 
| 11 | 
            +
            #puts test.source
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            def hello sym,sym2= "#{sym}", options={},*params,&block # the params
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              [1,2,3].each do |do_|
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                puts do_    # comment
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              puts "some code" # some comment
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            require 'debugger'
         | 
| 26 | 
            +
            #debugger
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            #TODO finish up method reader
         | 
| 29 | 
            +
            puts method(:hello).source
         | 
    
        data/lib/sourcerer.rb
    CHANGED
    
    | @@ -1,13 +1,16 @@ | |
| 1 1 | 
             
            #encoding: UTF-8
         | 
| 2 2 | 
             
            module Sourcerer
         | 
| 3 3 |  | 
| 4 | 
            +
              require File.join(File.dirname(__FILE__),"sourcerer","helpers")
         | 
| 5 | 
            +
              require File.join(File.dirname(__FILE__),"sourcerer","cache")
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              require File.join(File.dirname(__FILE__),"sourcerer","source_code")
         | 
| 8 | 
            +
              require File.join(File.dirname(__FILE__),"sourcerer","file")
         | 
| 9 | 
            +
             | 
| 4 10 | 
             
              require File.join(File.dirname(__FILE__),"sourcerer","proc_source")
         | 
| 5 11 | 
             
              require File.join(File.dirname(__FILE__),"sourcerer","proc_source_body")
         | 
| 6 12 | 
             
              require File.join(File.dirname(__FILE__),"sourcerer","proc_source_params")
         | 
| 7 13 |  | 
| 8 | 
            -
              require File.join(File.dirname(__FILE__),"sourcerer","string")
         | 
| 9 | 
            -
              require File.join(File.dirname(__FILE__),"sourcerer","file")
         | 
| 10 | 
            -
             | 
| 11 14 | 
             
              require File.join(File.dirname(__FILE__),"sourcerer","method")
         | 
| 12 15 | 
             
              require File.join(File.dirname(__FILE__),"sourcerer","proc")
         | 
| 13 16 |  | 
    
        data/lib/sourcerer/file.rb
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            class File
         | 
| 1 | 
            +
            class SourceFile < File
         | 
| 2 2 |  | 
| 3 3 | 
             
              # start read the file object on each line
         | 
| 4 4 | 
             
              # optionable an integer value to start read line at
         | 
| @@ -8,9 +8,13 @@ class File | |
| 8 8 | 
             
                  raise ArgumentError, "invalid line index"
         | 
| 9 9 | 
             
                end
         | 
| 10 10 | 
             
                begin
         | 
| 11 | 
            +
             | 
| 11 12 | 
             
                  line_num= 1
         | 
| 12 13 | 
             
                  text= self.read
         | 
| 13 14 | 
             
                  text.gsub!(/\r\n?/, "\n")
         | 
| 15 | 
            +
                  text.gsub!(';',"\n")
         | 
| 16 | 
            +
                  text.gsub!(/\bdo\b/,'{')
         | 
| 17 | 
            +
                  text.gsub!(/\bend\b/,'}')
         | 
| 14 18 | 
             
                  text.each_line do |*line|
         | 
| 15 19 | 
             
                    if line_num >= start_at
         | 
| 16 20 | 
             
                      block.call *line
         | 
| @@ -20,4 +24,4 @@ class File | |
| 20 24 | 
             
                end
         | 
| 21 25 | 
             
              end
         | 
| 22 26 |  | 
| 23 | 
            -
            end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            module Sourcerer
         | 
| 2 | 
            +
              class << self
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def raw_source obj
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  # default values
         | 
| 7 | 
            +
                  begin
         | 
| 8 | 
            +
                    block = 0
         | 
| 9 | 
            +
                    return_string = ProcSource.new
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  case RUBY_VERSION
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    when "1.9.3"
         | 
| 15 | 
            +
                      begin
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                        if obj.source_location.nil?
         | 
| 18 | 
            +
                          puts "WARN: Native Ruby 1.9.3 can't return sourceless code sources"
         | 
| 19 | 
            +
                          return "Proc.new { }"
         | 
| 20 | 
            +
                        end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                        SourceFile.open(File.expand_path(obj.source_location[0])
         | 
| 23 | 
            +
                        ).each_line_from obj.source_location[1] do |line|
         | 
| 24 | 
            +
                          line = SourceCode.new(line)
         | 
| 25 | 
            +
                          block += line.source_formater_for_line_sub
         | 
| 26 | 
            +
                          return_string.concat(line)
         | 
| 27 | 
            +
                          break if block == 0
         | 
| 28 | 
            +
                        end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                        return return_string
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                      end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  return nil
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def cache
         | 
| 40 | 
            +
                  Cache
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
    
        data/lib/sourcerer/method.rb
    CHANGED
    
    | @@ -1,73 +1,19 @@ | |
| 1 1 | 
             
            module Sourcerer
         | 
| 2 | 
            -
             | 
| 3 2 | 
             
              module MethodDSL
         | 
| 4 3 |  | 
| 5 | 
            -
             | 
| 6 4 | 
             
                # creatue a raw eval-able process source, so you can set
         | 
| 7 5 | 
             
                # the right bindings using the .to_proc call from String methods
         | 
| 8 6 | 
             
                def source
         | 
| 9 7 |  | 
| 10 | 
            -
                   | 
| 11 | 
            -
                   | 
| 12 | 
            -
                    return_string= Sourcerer::ProcSource.new
         | 
| 13 | 
            -
                    block= 0
         | 
| 14 | 
            -
                  end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  unless Sourcerer::ProcSource.source_cache[self.inspect].nil?
         | 
| 17 | 
            -
                    return Sourcerer::ProcSource.source_cache[self.inspect]
         | 
| 18 | 
            -
                  else
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                    if self.source_location.nil?
         | 
| 21 | 
            -
                      return nil
         | 
| 22 | 
            -
                    end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                    File.open(File.expand_path(self.source_location[0])
         | 
| 25 | 
            -
                    ).each_line_from self.source_location[1] do |line|
         | 
| 26 | 
            -
                      block += line.source_formater_for_line_sub
         | 
| 27 | 
            -
                      return_string.concat(line)
         | 
| 28 | 
            -
                      break if block == 0
         | 
| 29 | 
            -
                    end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                    begin
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                      if return_string.split("\n")[0].include? '('
         | 
| 34 | 
            -
                        return_string.sub!('(',' ')
         | 
| 35 | 
            -
                        return_string.sub!(')',' ')
         | 
| 36 | 
            -
                      end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                      args_to_replace = return_string.split("\n")[0].match(/\s*def\s*\S*\s*(.*)/).captures[0]
         | 
| 8 | 
            +
                  return_string= Sourcerer.raw_source(self).convert_from_method!
         | 
| 9 | 
            +
                  return return_string
         | 
| 39 10 |  | 
| 40 | 
            -
                      if args_to_replace != String.new
         | 
| 41 | 
            -
                        return_string.sub!(args_to_replace,"|#{args_to_replace}|")
         | 
| 42 | 
            -
                      end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                    rescue TypeError,NoMethodError
         | 
| 45 | 
            -
                      return nil
         | 
| 46 | 
            -
                    end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                    return_string.sub!(/\s*\bdef\s*[\w\S]*/,'Proc.new{')
         | 
| 49 | 
            -
                    return_string.sub!(/}[^}]*$/,"}")
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                    if !return_string.include?('Proc.new')
         | 
| 52 | 
            -
                      return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
         | 
| 53 | 
            -
                    end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                    if !self.source_location.nil?
         | 
| 56 | 
            -
                      Sourcerer::ProcSource.source_cache[self.inspect]= return_string
         | 
| 57 | 
            -
                    end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                    return return_string
         | 
| 60 | 
            -
                  end
         | 
| 61 11 | 
             
                end
         | 
| 62 | 
            -
             | 
| 63 12 | 
             
                alias :source_string :source
         | 
| 64 | 
            -
                alias :proc_source   :source
         | 
| 65 13 |  | 
| 66 14 | 
             
              end
         | 
| 67 | 
            -
             | 
| 68 15 | 
             
            end
         | 
| 69 16 |  | 
| 70 | 
            -
             | 
| 71 17 | 
             
            class Method
         | 
| 72 18 | 
             
              include Sourcerer::MethodDSL
         | 
| 73 19 | 
             
            end
         | 
    
        data/lib/sourcerer/proc.rb
    CHANGED
    
    | @@ -2,42 +2,11 @@ class Proc | |
| 2 2 |  | 
| 3 3 | 
             
              # create a raw eval-able process source, so you can set
         | 
| 4 4 | 
             
              # the right bindings using the .to_proc call from String methods
         | 
| 5 | 
            -
              def source
         | 
| 5 | 
            +
              def source # trim_comment= true
         | 
| 6 6 |  | 
| 7 | 
            -
                 | 
| 8 | 
            -
                 | 
| 9 | 
            -
                  return_string= Sourcerer::ProcSource.new
         | 
| 10 | 
            -
                  block= 0
         | 
| 11 | 
            -
                end
         | 
| 7 | 
            +
                return_string= Sourcerer.raw_source(self).convert_from_proc!
         | 
| 8 | 
            +
                return return_string
         | 
| 12 9 |  | 
| 13 | 
            -
                unless Sourcerer::ProcSource.source_cache[self.inspect].nil?
         | 
| 14 | 
            -
                  return Sourcerer::ProcSource.source_cache[self.inspect]
         | 
| 15 | 
            -
                else
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  if self.source_location.nil?
         | 
| 18 | 
            -
                    return "Proc.new { }"
         | 
| 19 | 
            -
                  end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                  File.open(File.expand_path(self.source_location[0])
         | 
| 22 | 
            -
                  ).each_line_from self.source_location[1] do |line|
         | 
| 23 | 
            -
                    block += line.source_formater_for_line_sub
         | 
| 24 | 
            -
                    return_string.concat(line)
         | 
| 25 | 
            -
                    break if block == 0
         | 
| 26 | 
            -
                  end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  return_string.sub!(/^[\w\W]*Proc.new\s*{/,'Proc.new{')
         | 
| 29 | 
            -
                  return_string.sub!(/}[^}]*$/,"}")
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  if !return_string.include?('Proc.new')
         | 
| 32 | 
            -
                    return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
         | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  if !self.source_location.nil?
         | 
| 36 | 
            -
                    Sourcerer::ProcSource.source_cache[self.inspect]= return_string
         | 
| 37 | 
            -
                  end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                  return return_string
         | 
| 40 | 
            -
                end
         | 
| 41 10 | 
             
              end
         | 
| 42 11 | 
             
              alias :source_string :source
         | 
| 43 12 |  | 
| @@ -1,5 +1,5 @@ | |
| 1 1 | 
             
            module Sourcerer
         | 
| 2 | 
            -
              class ProcSource <  | 
| 2 | 
            +
              class ProcSource < SourceCode
         | 
| 3 3 |  | 
| 4 4 | 
             
                class << self
         | 
| 5 5 | 
             
                  attr_accessor :source_cache
         | 
| @@ -8,7 +8,6 @@ module Sourcerer | |
| 8 8 | 
             
                self.source_cache= Hash.new
         | 
| 9 9 | 
             
                self.eval_keys= Array.new
         | 
| 10 10 |  | 
| 11 | 
            -
             | 
| 12 11 | 
             
                def self.build(source_code_to_be_wrappered,*params_obj_array)
         | 
| 13 12 | 
             
                  self.new(source_code_to_be_wrappered).wrapper_around!(*params_obj_array)
         | 
| 14 13 | 
             
                end
         | 
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            module Sourcerer
         | 
| 2 | 
            +
              class SourceCode < String
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                # return the number how often the str is with in the self
         | 
| 5 | 
            +
                # by default with \b regex border
         | 
| 6 | 
            +
                def frequency(str)
         | 
| 7 | 
            +
                  begin
         | 
| 8 | 
            +
                    if str.class == String
         | 
| 9 | 
            +
                      str= '\b'+str+'\b'
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                  self.scan(/#{str}/).count
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                # this is a helper to create source strings from procs
         | 
| 16 | 
            +
                def source_formater_for_line_sub trim_comment_out= true
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  if trim_comment_out == true
         | 
| 19 | 
            +
                    trim_comment= self.match(/^.*#/)
         | 
| 20 | 
            +
                    unless trim_comment.nil?
         | 
| 21 | 
            +
                      self.replace trim_comment[0][0..(trim_comment[0].length-2)].concat("\n")
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  self.frequency(/{/)+
         | 
| 26 | 
            +
                      self.frequency(/def/)-
         | 
| 27 | 
            +
                      self.frequency(/}/)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def convert_from_proc!
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  self.sub!(/^[\w =]*Proc.new\s*{ */,'Proc.new { ')
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  return self
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
                def convert_from_method!
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  #self.sub!
         | 
| 41 | 
            +
                  the_params= self.scan(/ *def *[\w]*[\( ] *(.*)/)[0][0]
         | 
| 42 | 
            +
                  puts the_params.inspect
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  self.sub!(
         | 
| 45 | 
            +
                      self.split("\n")[0],
         | 
| 46 | 
            +
                      "Proc.new { |#{the_params}|"
         | 
| 47 | 
            +
                  )
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  return self
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sourcerer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.5. | 
| 4 | 
            +
              version: 0.5.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Adam Luzsi
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-01- | 
| 11 | 
            +
            date: 2014-01-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: ! ' DSL for for simple to use proc source generating from methods, unbound
         | 
| 14 14 | 
             
              methods and of course Proc/lambda. It will allow you to play with the source or
         | 
| @@ -26,16 +26,19 @@ files: | |
| 26 26 | 
             
            - Rakefile
         | 
| 27 27 | 
             
            - VERSION
         | 
| 28 28 | 
             
            - examples/fun_with_procs_and_methods.rb
         | 
| 29 | 
            +
            - examples/simple_test.rb
         | 
| 29 30 | 
             
            - files.rb
         | 
| 30 31 | 
             
            - lib/source.rb
         | 
| 31 32 | 
             
            - lib/sourcerer.rb
         | 
| 33 | 
            +
            - lib/sourcerer/cache.rb
         | 
| 32 34 | 
             
            - lib/sourcerer/file.rb
         | 
| 35 | 
            +
            - lib/sourcerer/helpers.rb
         | 
| 33 36 | 
             
            - lib/sourcerer/method.rb
         | 
| 34 37 | 
             
            - lib/sourcerer/proc.rb
         | 
| 35 38 | 
             
            - lib/sourcerer/proc_source.rb
         | 
| 36 39 | 
             
            - lib/sourcerer/proc_source_body.rb
         | 
| 37 40 | 
             
            - lib/sourcerer/proc_source_params.rb
         | 
| 38 | 
            -
            - lib/sourcerer/ | 
| 41 | 
            +
            - lib/sourcerer/source_code.rb
         | 
| 39 42 | 
             
            - sourcerer.gemspec
         | 
| 40 43 | 
             
            - test/test.rb
         | 
| 41 44 | 
             
            homepage: https://github.com/adamluzsi/sourcerer
         | 
| @@ -53,9 +56,9 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 53 56 | 
             
                  version: '0'
         | 
| 54 57 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 55 58 | 
             
              requirements:
         | 
| 56 | 
            -
              - - ! ' | 
| 59 | 
            +
              - - ! '>='
         | 
| 57 60 | 
             
                - !ruby/object:Gem::Version
         | 
| 58 | 
            -
                  version:  | 
| 61 | 
            +
                  version: '0'
         | 
| 59 62 | 
             
            requirements: []
         | 
| 60 63 | 
             
            rubyforge_project: 
         | 
| 61 64 | 
             
            rubygems_version: 2.2.1
         | 
    
        data/lib/sourcerer/string.rb
    DELETED
    
    | @@ -1,25 +0,0 @@ | |
| 1 | 
            -
            class String
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              # return the number how often the str is with in the self
         | 
| 4 | 
            -
              # by default with \b regex border
         | 
| 5 | 
            -
              def frequency(str)
         | 
| 6 | 
            -
                begin
         | 
| 7 | 
            -
                  if str.class == String
         | 
| 8 | 
            -
                    str= '\b'+str+'\b'
         | 
| 9 | 
            -
                  end
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
                self.scan(/#{str}/).count
         | 
| 12 | 
            -
              end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
              # this is a helper to create source strings from procs
         | 
| 15 | 
            -
              def source_formater_for_line_sub
         | 
| 16 | 
            -
                self.gsub!(';',"\n")
         | 
| 17 | 
            -
                self.gsub!(/\bdo\b/,'{')
         | 
| 18 | 
            -
                self.gsub!(/\bend\b/,'}')
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                self.frequency(/{/)+
         | 
| 21 | 
            -
                    self.frequency(/def/)-
         | 
| 22 | 
            -
                    self.frequency(/}/)
         | 
| 23 | 
            -
              end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            end
         |