Skip to content

Commit

Permalink
Merge pull request #204 from sue445/feature/reiwa
Browse files Browse the repository at this point in the history
Impl `heisei?` and `reiwa?` methods
  • Loading branch information
sue445 authored Jun 1, 2019
2 parents 6241987 + 2d34ac6 commit fb2806d
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,27 @@ Go!プリンセスプリキュア

* `has_birthday?` is alias to `have_birthday?`

### `Rubicure::Girl#heisei?` and `Rubicure::Girl#reiwa?`
```ruby
>> Cure.star.heisei?
=> true
>> Cure.star.reiwa?
=> false
```

### `Rubicure::Series#heisei?` and `Rubicure::Series#reiwa?`
```ruby
>> Precure.hugtto.heisei?
=> true
>> Precure.hugtto.reiwa?
=> false

>> Precure.star_twinkle.heisei?
=> true
>> Precure.star_twinkle.reiwa?
=> true
```

## More reference
http://rubydoc.info/gems/rubicure/frames

Expand Down
1 change: 1 addition & 0 deletions lib/rubicure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "hashie"
require "rubicure/version"
require "rubicure/concerns/util"
require "rubicure/concerns/gengou"
require "rubicure/series"
require "rubicure/girl"
require "rubicure/core"
Expand Down
17 changes: 17 additions & 0 deletions lib/rubicure/concerns/gengou.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Rubicure
module Concerns
module Gengou
refine Date do
# Whether current date is Heisei
def heisei?
Date.new(1989, 1, 8) <= self && self <= Date.new(2019, 4, 30)
end

# Whether current date is Reiwa
def reiwa?
Date.new(2019, 5, 1) <= self
end
end
end
end
end
12 changes: 12 additions & 0 deletions lib/rubicure/girl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Rubicure
class Girl < Hash # rubocop:disable Metrics/ClassLength
include Hashie::Extensions::MethodAccess

using Rubicure::Concerns::Gengou

ATTRIBUTES = [
:girl_name,
:human_name,
Expand Down Expand Up @@ -161,6 +163,16 @@ def full_name
human_full_name.presence || human_name
end

# Whether Heisei precure
def heisei?
created_date.heisei?
end

# Whether Reiwa precure
def reiwa?
created_date.reiwa?
end

ATTRIBUTES.each do |attribute|
define_method attribute do
if @current_transform_style
Expand Down
15 changes: 15 additions & 0 deletions lib/rubicure/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Series < Hash
include Rubicure::Concerns::Util
include Enumerable

using Rubicure::Concerns::Gengou

@cache = {}
@config = nil

Expand Down Expand Up @@ -71,6 +73,19 @@ def to_json(*_args)
original_hash.to_json
end

# Whether Heisei precure
def heisei?
started_date.heisei? || ended_date.heisei?
end

# Whether Reiwa precure
def reiwa?
# TODO: Remove after StarTwinkle Precure is finished
return true unless has_key?(:ended_date)

started_date.reiwa? || ended_date.reiwa?
end

class << self
# @return [Array<Symbol>]
def names
Expand Down
37 changes: 37 additions & 0 deletions spec/rubicure/concerns/gengou_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
describe Rubicure::Concerns::Gengou do
using Rubicure::Concerns::Gengou

describe "Date#heisei?" do
subject { date(str).heisei? }

using RSpec::Parameterized::TableSyntax

where(:str, :expected) do
"1989-01-07" | false
"1989-01-08" | true
"2019-04-30" | true
"2019-05-01" | false
end

with_them do
it { should eq expected }
end
end

describe "Date#reiwa?" do
subject { date(str).reiwa? }

using RSpec::Parameterized::TableSyntax

where(:str, :expected) do
"1989-01-07" | false
"1989-01-08" | false
"2019-04-30" | false
"2019-05-01" | true
end

with_them do
it { should eq expected }
end
end
end
15 changes: 14 additions & 1 deletion spec/rubicure/girl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
let(:human_name) { "黄瀬やよい" }
let(:precure_name) { "キュアピース" }
let(:cast_name) { "金元寿子" }
let(:created_date) { "2012-02-19" }
let(:created_date) { date("2012-02-19") }
let(:extra_names) { %w[プリンセスピース ウルトラピース] }
let(:color) { "yellow" }
let(:transform_message) do
Expand Down Expand Up @@ -331,4 +331,17 @@
it { should eq "黄瀬やよい" }
end
end

describe "#heisei?" do
subject { girl.heisei? }

it { should eq true }
end

describe "#reiwa?" do
subject { girl.reiwa? }

# TODO: Add reiwa precure test after cure cosmo is added
it { should eq false }
end
end
34 changes: 34 additions & 0 deletions spec/rubicure/series_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,38 @@

it { should eq json.squish }
end

describe "#heisei?" do
subject { series.heisei? }

using RSpec::Parameterized::TableSyntax

let(:series) { Rubicure::Series.find(series_name) }

where(:series_name, :expected) do
:hugtto | true
:star_twinkle | true
end

with_them do
it { should eq expected }
end
end

describe "#reiwa?" do
subject { series.reiwa? }

using RSpec::Parameterized::TableSyntax

let(:series) { Rubicure::Series.find(series_name) }

where(:series_name, :expected) do
:hugtto | false
:star_twinkle | true
end

with_them do
it { should eq expected }
end
end
end

0 comments on commit fb2806d

Please sign in to comment.