Skip to content

Commit

Permalink
Port number_with_delimiter method from ActiveSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
rwojsznis authored and mperham committed Mar 21, 2018
1 parent 26253ed commit e29635e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions spec/web_helpers_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "./spec_helper"

class ClassWithWebHelpers
include Sidekiq::WebHelpers
end

describe Sidekiq::WebHelpers do
describe "#number_with_delimiter" do
it "returns formatted number with delimiter" do
klass = ClassWithWebHelpers.new

klass.number_with_delimiter(1).should eq "1"
klass.number_with_delimiter(123).should eq "123"
klass.number_with_delimiter(1234).should eq "1,234"
klass.number_with_delimiter(12345).should eq "12,345"
klass.number_with_delimiter(123456).should eq "123,456"
klass.number_with_delimiter(1234567).should eq "1,234,567"
klass.number_with_delimiter(12345678).should eq "12,345,678"
klass.number_with_delimiter(123456789).should eq "123,456,789"
end
end
end
8 changes: 4 additions & 4 deletions src/sidekiq/web_helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ module Sidekiq

def display_args(args, truncate_after_chars = 2000)
h args[1..-2]
#args.map do |arg|
#h(truncate(to_display(arg), truncate_after_chars))
#end.join(", ")
# args.map do |arg|
# h(truncate(to_display(arg), truncate_after_chars))
# end.join(", ")
end

def csrf_tag
Expand Down Expand Up @@ -172,7 +172,7 @@ module Sidekiq
end

def number_with_delimiter(number)
number.to_s
number.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
end

def h(text)
Expand Down

0 comments on commit e29635e

Please sign in to comment.