Skip to content
Browse files

Merge pull request #6 from joevandyk/master

Remove whitespace
  • Loading branch information...
2 parents bbe0890 + 7fcb0a2 commit 39dc650ed78564e7c2c55850aa349e03bed3c7cb @peleteiro committed Jun 24, 2012
Showing with 39 additions and 39 deletions.
  1. +4 −4 lib/duration.rb
  2. +2 −2 lib/duration/mongoid.rb
  3. +1 −1 lib/ruby-duration.rb
  4. +1 −1 test/fixtures/locales/pt.yml
  5. +24 −24 test/test_duration.rb
  6. +2 −2 test/test_i18n.rb
  7. +5 −5 test/test_mongoid.rb
View
8 lib/duration.rb
@@ -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
@@ -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:
@@ -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
@@ -219,4 +219,4 @@ def i18n_for(singular)
I18n.t(label, :scope => :ruby_duration, :default => label.to_s)
end
-end
+end
View
4 lib/duration/mongoid.rb
@@ -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
@@ -33,4 +33,4 @@ def serialize(value)
end
end
end
-end
+end
View
2 lib/ruby-duration.rb
@@ -1,2 +1,2 @@
# -*- encoding: utf-8 -*-
-require "#{File.dirname(__FILE__)}/duration"
+require "#{File.dirname(__FILE__)}/duration"
View
2 test/fixtures/locales/pt.yml
@@ -9,4 +9,4 @@ pt:
day: dia
days: dias
week: semana
- weeks: semanas
+ weeks: semanas
View
48 test/test_duration.rb
@@ -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)
@@ -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
@@ -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
View
4 test/test_i18n.rb
@@ -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
@@ -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
View
10 test/test_mongoid.rb
@@ -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
@@ -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 }
@@ -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

0 comments on commit 39dc650

Please sign in to comment.
Something went wrong with that request. Please try again.