Giter Site home page Giter Site logo

ruby_beautifier's Introduction

A ruby code beautifier/prettifier cleans ruby code for you [and give it the right indentation, etc.]

What it does:

you run rbeautify on poorly-aligned code, like

    def go
    if 3
    stuff
    end
    end

and it automatically converts said code to

def go
  if 3
    stuff
  end
end

Quite convenient for those of us who edit using editors without auto format.  It also
helps find indentation mismatches [i.e. missing end's and }'s ] by cleaning
up the code so you can see scopes, and warning you where it sees mismatches [similar to ruby19 -w but better].

Many thanks to the original author [I just gemif-ied his existing script].
http://www.arachnoid.com/ruby/rubyBeautifier.html

Installation:
gem sources -a http://gems.github.com
sudo gem install rogerdpack-rbeautify

Usage:
rbeautify <script name>

Feedback welcome rogerdpack on github

ruby_beautifier's People

Contributors

rdp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ruby_beautifier's Issues

fails again

      input = <<-EOL
# comments can go after a # on any line.
"mutes" => [
  "00:00:01.0", "00:00:02.0", "da..",
],

"blank_outs" => [
  "01:01:00.0" , "01:02:00.0", "violent scene of some sort"
],
"disk_unique_id" => "#{md5}",
"title" => "#{volume}",
"dvd_title_track" => "1" # most DVD's use title 1 for the main film.  Some don't though.  The correct number is discoverable by opening the film in VLC and choosing "playback -> title" while watching the main feature.  If its not 1, then change this here.
        EOL
 

fails thusly

class ParseFast

  def initialize filename
    @filename = filename
  end

  # currently returns full download time
  #
  # let's return a hash, like
  # {:download_time => [float or nil], :peer_bytes => x, :origin_bytes => y}
  #
  def go use_this_test_string = nil
    float = /\d+.\d+/
    start_regex = /(#{float})._starting up logger/
    end_regex = /(#{float})._DONE WITH WHOLE FILE/

```
cs_straight = /#{float}.*cs straight.*just received (\d+)B/

bytes = [[cs_straight, :cs_straight]]

starty = nil
endy = nil
stats = {}
stats[:cs_straight] = 0
stats[:cs_p2p] = 0


(use_this_test_string || File.read(@filename)).lines {|line|

  if !starty && line =~ start_regex
    puts line, 'start line' if $VERBOSE
    starty = $1.to_f
  else
    begin # pesky encoding errors
      if !endy && line =~ end_regex
        puts line if $VERBOSE
        endy = $1.to_f
      else
        for regex, name in bytes
          if line =~ regex
            puts 'victory!'
            stats[name] += $1.to_i
            break # somewhat helpful...
          end
        end
      end
    rescue => e # encoding error...
      puts line, line.inspect
    end
  end
}

stats[:download_time] = if endy && starty
puts endy - starty
endy - starty
```

  else
    nil
  end

  stats[:all_cs_bytes] = stats[:cs_straight] + stats[:cs_p2p]

  stats
end

end

if **FILE** == $0
puts ParseFast.new(ARGV[0]).go
end

format this better

long_value = {:assert_value_type => 'T_FIXNUM', :convert_values_from_ruby => "FIX2LONG",
:convert_values_to_ruby => "LONG2FIX", :value_type => "long"}

fails on this code

  def focus_word(focus_segment)
    focus_world = ''
    char = focus_segment[-1..-1]
  while [")","]","}"].include?(char)
    char=focus_segment[-2..-2]
    focus_segment = focus_segment[0..-2]
  end
  j = focus_segment.length - 1
  while !["\s","\t",";",",","(","[","{",">"].include?(char) && j >= 0
    focus_world = "#{char}#{focus_world}"
    j=j-1
    char = focus_segment[j..j]
  end
  focus_world
end

this becomes ugly

promo = Promotion.find(
:first,
:conditions => ["code = ?", self.promotion_code]
)

fails on this code

puts File.dirname(FILE) + '/../test_helper'
require File.dirname(FILE) + '/../test_helper'

class StoreControllerTest < ActionController::TestCase
def test_with_no_promotions_should_end_up_full_price
# get :checkout
# assert_redirects TODO assert_response :success
# assert_not_nil assigns(:gift_certs)
# redirects since you hain't got nothin' checked out!
end

def test_checkout_posts_at_all
cart = Cart.new
p = Product.create! :code => 'code1', :quantity => 1000, :name => 'name', :price => 1, :date_available => Time.now rescue Product.first cart.add_product p
a = a = Preference.find_by_name('cc_processor')
a.value = Preference::CC_PROCESSORS[2]
a.save
post :checkout, {"commit"=>"Submit Order Information", "action"=>"checkout", "controller"=>"store", "shipping_address"=>{"city"=>"", "zip"=>"", "country_id"=>"1",
"first_name"=>"", "telephone"=>"", "last_name"=>"", "address"=>"", "state"=>""}, "billing_address"=>{"city"=>"t", "zip"=>"84601", "country_id"=>"1", "first_name"=>"t", "telephone"=>"8013776152", "last_name"=>"t", "address"=>"t", "state"=>"ut"},
"order_user"=>{"subscribed_to_email"=>"1", "email_address"=>"[email protected]"}}, {:cart => cart}
assert_redirected_to :action => 'select_shipping_method'
end

end

yes indeed

failure

  context "with variables warnings" do
   for warning in [50, 75, 00]

```
it "should return warning with any at #{warning}" do
  for x in [warning = 1, warning]
    a = VerifyDisk.new nil, setup(x, 99)
    got = a.verify
    got.should == ['WARNING ' + {"lb"=>x, "sb"=>99}.inspect, 1]
  end
end
```

  end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.