Skip to content

Commit

Permalink
Merge pull request #6 from joevandyk/master
Browse files Browse the repository at this point in the history
Remove whitespace
  • Loading branch information
peleteiro committed Jun 24, 2012
2 parents bbe0890 + 7fcb0a2 commit 39dc650
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions lib/duration.rb
Expand Up @@ -71,7 +71,7 @@ def /(other)
def %(other)
Duration.new(@total % other.to_i)
end

%w(minutes hours days).each do |meth|
define_method("total_#{meth}") { @total / MULTIPLES[meth.to_sym] }
end
Expand Down Expand Up @@ -134,7 +134,7 @@ def present?
#
# I18n.load_path << "path/to/your/locale"
# I18n.locale = :your_locale
#
#
# And you must use the following structure (example) for your locale file:
# pt:
# ruby_duration:
Expand Down Expand Up @@ -182,7 +182,7 @@ def format(format_str)

alias_method :to_i, :total
alias_method :strftime, :format

private

# Calculates the duration from seconds and figures out what the actual
Expand Down Expand Up @@ -219,4 +219,4 @@ def i18n_for(singular)

I18n.t(label, :scope => :ruby_duration, :default => label.to_s)
end
end
end
4 changes: 2 additions & 2 deletions lib/duration/mongoid.rb
Expand Up @@ -6,7 +6,7 @@ module Mongoid
module Fields
class Duration
include Mongoid::Fields::Serializable

# Deserialize a Duration given the amount of seconds stored by Mongodb
#
# @param [Integer, nil] duration in seconds
Expand All @@ -33,4 +33,4 @@ def serialize(value)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ruby-duration.rb
@@ -1,2 +1,2 @@
# -*- encoding: utf-8 -*-
require "#{File.dirname(__FILE__)}/duration"
require "#{File.dirname(__FILE__)}/duration"
2 changes: 1 addition & 1 deletion test/fixtures/locales/pt.yml
Expand Up @@ -9,4 +9,4 @@ pt:
day: dia
days: dias
week: semana
weeks: semanas
weeks: semanas
48 changes: 24 additions & 24 deletions test/test_duration.rb
Expand Up @@ -27,29 +27,29 @@
assert_equal 219, d.total_hours
assert_equal 9, d.total_days
end

describe "mathematical operations" do

it "should +" do
assert_equal Duration.new(15), Duration.new(10) + 5
assert_equal Duration.new(15), Duration.new(10) + Duration.new(5)
end

it "should -" do
assert_equal Duration.new(5), Duration.new(10) - 5
assert_equal Duration.new(5), Duration.new(10) - Duration.new(5)
end

it "should *" do
assert_equal Duration.new(20), Duration.new(10) * 2
assert_equal Duration.new(20), Duration.new(10) * Duration.new(2)
end

it "should /" do
assert_equal Duration.new(5), Duration.new(10) / 2
assert_equal Duration.new(5), Duration.new(10) / Duration.new(2)
end

it "should %" do
assert_equal Duration.new(1), Duration.new(10) % 3
assert_equal Duration.new(1), Duration.new(10) % Duration.new(3)
Expand All @@ -66,79 +66,79 @@
d = Duration.new(:weeks => 1, :days => 1, :hours => 1, :minutes => 1, :seconds => 1)
assert_equal "1 week 1 day 1 hour 1 minute 1 second", d.format("%w %~w %d %~d %h %~h %m %~m %s %~s")
end

it "should display total seconds" do
d = Duration.new(:hours => 1, :minutes => 15)
assert_equal "4500 seconds", d.format("%tsu")
end

it "should display total seconds in plural form when needed" do
d = Duration.new(:minutes => 1, :seconds => 1)
assert_equal "61 seconds", d.format("%tsu")
end

it "should display total minutes as number" do
d = Duration.new(:hours => 1, :minutes => 15)
assert_equal "75", d.format("%tm")
end

it 'should display total minutes with unit' do
d = Duration.new(:hours => 1, :minutes => 15)
assert_equal "75 minutes", d.format("%tmu")
end

it "should display total minutes in plural form when needed" do
d = Duration.new(:hours => 1, :minutes => 1)
assert_equal "61 minutes", d.format("%tmu")
end

it "should display total hours as number" do
d = Duration.new(:days => 2, :hours => 1)
assert_equal "49", d.format("%th")
end

it 'should display total hours with unit' do
d = Duration.new(:days => 2, :hours => 2)
assert_equal "50 hours", d.format("%thu")
end

it "should display total hours in plural form when needed" do
d = Duration.new(:days => 1, :hours => 1)
assert_equal "25 hours", d.format("%thu")
end

it "should display total days as number" do
d = Duration.new(:weeks => 1, :days => 3)
assert_equal "10", d.format("%td")
end

it 'should display total days with unit' do
d = Duration.new(:weeks => 1, :days => 2)
assert_equal "9 days", d.format("%tdu")
end

it "should display total days in plural form when needed" do
d = Duration.new(:weeks => 1, :days => 1)
assert_equal "8 days", d.format("%tdu")
end
end

describe "#iso_6801" do
it "should format seconds" do
d = Duration.new(:seconds => 1)
assert_equal "PT1S", d.iso8601
end

it "should format minutes" do
d = Duration.new(:minutes => 1)
assert_equal "PT1M", d.iso8601
end

it "should format hours" do
d = Duration.new(:hours => 1)
assert_equal "PT1H", d.iso8601
end

it "should format days" do
d = Duration.new(:days => 1)
assert_equal "P1D", d.iso8601
Expand All @@ -164,17 +164,17 @@
end

end

describe "utilities methods" do
it "should respond to blank?" do
assert Duration.new.blank?
refute Duration.new(1).blank?
end

it "should respond to present?" do
refute Duration.new.present?
assert Duration.new(1).present?
end
end

end
end
4 changes: 2 additions & 2 deletions test/test_i18n.rb
Expand Up @@ -3,7 +3,7 @@

I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'locales', 'pt.yml')

describe "I18n" do
describe "I18n" do
describe "when the locale is pt" do
before do
I18n.locale = :pt
Expand All @@ -30,7 +30,7 @@
end

it "should translate to horas" do
assert_equal "horas", Duration.new.format("%~h")
assert_equal "horas", Duration.new.format("%~h")
end

it "should translate to dia" do
Expand Down
10 changes: 5 additions & 5 deletions test/test_mongoid.rb
Expand Up @@ -11,7 +11,7 @@ class MyModel
end
@model = MyModel.new
end

describe "assigning an integer value" do
it "should return the duration given the total in seconds" do
@model.duration = 90
Expand All @@ -23,14 +23,14 @@ class MyModel
assert_nil @model.duration
end
end

describe "assigning an array" do
it "should return nil" do
@model.duration = [1,2,3]
assert_nil @model.duration
end
end

describe "assigning a valid hash" do
it "should return total seconds given a duration in hash" do
@model.duration = { :minutes => 1, :seconds => 30 }
Expand Down Expand Up @@ -59,10 +59,10 @@ class MyModel
it "should return total seconds given a duration in string" do
@model.duration = "10"
assert_equal Duration.new(10), @model.duration

@model.duration = "10string"
assert_equal Duration.new(10), @model.duration

@model.duration = "string"
assert_equal Duration.new(0), @model.duration
end
Expand Down

0 comments on commit 39dc650

Please sign in to comment.