diff --git a/lib/time/iterator.rb b/lib/time/iterator.rb index 8b57695..69817b9 100644 --- a/lib/time/iterator.rb +++ b/lib/time/iterator.rb @@ -1,15 +1,8 @@ require "active_support" require "active_support/core_ext/integer/time" +require_relative "iterator/core_ext/numeric" require_relative "iterator/core_ext/time" -# Inject 3.quarters -class Numeric - def quarter - (3 * self).months - end - alias quarters quarter -end - class Time # Time iteration, and extra Time methods. module Iterator diff --git a/lib/time/iterator/core_ext/numeric.rb b/lib/time/iterator/core_ext/numeric.rb new file mode 100644 index 0000000..8739872 --- /dev/null +++ b/lib/time/iterator/core_ext/numeric.rb @@ -0,0 +1,7 @@ +# Inject 3.quarters +class Numeric + def quarter + (3 * self).months + end + alias quarters quarter +end diff --git a/spec/time/core_ext/numeric_spec.rb b/spec/time/core_ext/numeric_spec.rb new file mode 100644 index 0000000..78d7ec7 --- /dev/null +++ b/spec/time/core_ext/numeric_spec.rb @@ -0,0 +1,13 @@ +RSpec.describe Numeric do + let(:time) { Time.now } + + describe '#quarter(s)' do + [:quarter, :quarters].each do |method| + it 'adds 3 months per quarter' do + expect( time + 1.send(method) ).to eq time + 3.months + expect( time + 3.send(method) ).to eq time + 9.months + expect( time + 4.send(method) ).to eq time + 1.year + end + end + end +end diff --git a/spec/time/iterator_spec.rb b/spec/time/iterator_spec.rb index 290db9e..5fbf526 100644 --- a/spec/time/iterator_spec.rb +++ b/spec/time/iterator_spec.rb @@ -1,16 +1,6 @@ RSpec.describe Time::Iterator do let(:time) { Time.now } - describe '#quarter(s)' do - [:quarter, :quarters].each do |method| - it 'adds 3 months per quarter' do - expect( time + 1.send(method) ).to eq time + 3.months - expect( time + 3.send(method) ).to eq time + 9.months - expect( time + 4.send(method) ).to eq time + 1.year - end - end - end - describe '#iterate' do it 'uses an Enumerator' do expect( time.iterate(by: :day) ).to be_a(Enumerator)