Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[modify] able to specify "expires_in" at config/rss.yml
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class SS::Duration | ||
def self.parse(name) | ||
num, unit = name.to_s.split('.', 2) | ||
raise "malformed duration: #{name}" if !num.numeric? | ||
|
||
num = num.to_i | ||
case unit.singularize | ||
when "year" | ||
num.years | ||
when "month" | ||
num.months | ||
when "week" | ||
num.weeks | ||
when "day" | ||
num.days | ||
when "hour" | ||
num.hours | ||
when "minute" | ||
num.minutes | ||
when "second" | ||
num.seconds | ||
else | ||
raise "malformed duration: #{name}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
describe SS::Duration do | ||
describe ".parse" do | ||
context "with valid durations" do | ||
it do | ||
expect(SS::Duration.parse("1.year")).to eq 1.year | ||
expect(SS::Duration.parse("2.years")).to eq 2.years | ||
expect(SS::Duration.parse("1.month")).to eq 1.month | ||
expect(SS::Duration.parse("2.months")).to eq 2.months | ||
expect(SS::Duration.parse("1.day")).to eq 1.day | ||
expect(SS::Duration.parse("2.days")).to eq 2.days | ||
expect(SS::Duration.parse("1.hour")).to eq 1.hour | ||
expect(SS::Duration.parse("2.hours")).to eq 2.hours | ||
expect(SS::Duration.parse("1.minute")).to eq 1.minute | ||
expect(SS::Duration.parse("2.minutes")).to eq 2.minutes | ||
expect(SS::Duration.parse("1.second")).to eq 1.second | ||
expect(SS::Duration.parse("2.seconds")).to eq 2.seconds | ||
end | ||
end | ||
|
||
context "with invalid unit" do | ||
it do | ||
expect { SS::Duration.parse("1.decade") }.to raise_error RuntimeError, "malformed duration: 1.decade" | ||
end | ||
end | ||
|
||
context "with non-number" do | ||
it do | ||
expect { SS::Duration.parse("hello.days") }.to raise_error RuntimeError, "malformed duration: hello.days" | ||
end | ||
end | ||
end | ||
end |