Skip to content

Commit

Permalink
seperator patch and better naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goebel authored and Josh Goebel committed May 18, 2008
1 parent 1d7ddc9 commit 8a99e9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ year that you started.

Example: With the assumption that the current year was 2008

<%= year_range(2005) -%> # => 2005-2008
<%= year_range(2005, '&mdash;') -%> # => 2005&mdash;2008
<%= year_range(2008) -%> # => 2008 (just returns current year)
<%= current_year_range(2005) -%> # => 2005-2008
<%= current_year_range(2005, '&mdash;') -%> # => 2005&mdash;2008
<%= current_year_range(2008) -%> # => 2008 (just returns current year)

You can access the code here:

Expand Down
4 changes: 3 additions & 1 deletion lib/year_after_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ def current_year
Time.now.year
end

def year_range( start_year = current_year, separator = '-' )
def current_year_range( start_year = current_year, separator = '-' )
[start_year, current_year].sort.uniq.join(separator)
end

alias :year_range :current_year_range
end
end
5 changes: 3 additions & 2 deletions spec/year_after_year_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
end

it 'should return a range of years when provided a start year' do
year_range(2004).should == '2004-2006'
current_year_range(2004).should == '2004-2006'
end

it "should return a range of years with the specified separator" do
year_range(2004, '&mdash;').should == '2004&mdash;2006'
current_year_range(2004, '&mdash;').should == '2004&mdash;2006'
end

it 'should return only the current year if the start year is the same' do
current_year_range(2006).should == '2006'
year_range(2006).should == '2006'
end
end

0 comments on commit 8a99e9e

Please sign in to comment.