Skip to content

Commit

Permalink
Merge 69a3e79 into 031ba87
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Dec 17, 2013
2 parents 031ba87 + 69a3e79 commit 2e4ae0e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rubicure/girl.rb
Expand Up @@ -15,6 +15,10 @@ def initialize(human_name: nil, precure_name: nil, transform_message: nil, extra
@state_names += @extra_names unless @extra_names.empty?
end

def == (other)
other.is_a?(self.class) && self.human_name == other.human_name
end

# @return [String] name of current form
def name
@state_names[@current_state]
Expand Down
11 changes: 11 additions & 0 deletions lib/rubicure/series.rb
Expand Up @@ -5,6 +5,17 @@ class Series < Hash
@@cache = {}
@@config = nil

def === (other)
case other
when self.class
self == other
when Rubicure::Girl
self.girls.include? other
else
false
end
end

# @param [Time,Date,String] arg Time, Date or date like String (ex. "2013-12-16")
def on_air?(arg)
date = to_date(arg)
Expand Down
46 changes: 46 additions & 0 deletions spec/girl_spec.rb
Expand Up @@ -64,6 +64,52 @@
end
end

describe "#==" do
let(:girl){
Rubicure::Girl.new(
human_name: human_name,
precure_name: precure_name,
extra_names: extra_names,
transform_message: transform_message
)
}

let(:human_name) { "黄瀬やよい" }
let(:precure_name) { "キュアピース" }
let(:extra_names) { %w(プリンセスピース ウルトラピース) }
let(:transform_message){
<<EOF
プリキュアスマイルチャージ!
GO! GO! Let's GO ピース!
ピカピカピカリンジャンケンポン! キュアピース!
EOF
}

context "same object" do
subject{ girl == girl }
it{ should be true }
end

context "copied object" do
subject{ girl == copied_girl }
let(:copied_girl){ girl.dup }
it{ should be true }
end

context "precure and human" do
subject{ girl == transformed_girl }
let(:transformed_girl){ girl.dup.transform! }
it{ expect(girl.name).not_to eq transformed_girl.name }
it{ should be true }
end

context "other precure" do
subject{ girl == other_girl }
let(:other_girl){ Rubicure::Girl.find(:passion) }
it{ should be false }
end
end

describe "#find" do
subject{ Rubicure::Girl.find(girl_name) }

Expand Down
27 changes: 27 additions & 0 deletions spec/series_spec.rb
Expand Up @@ -68,6 +68,33 @@
]
}

describe "#===" do
let(:series){ Rubicure::Series.find(series_name) }
let(:series_name){ :smile }
let(:girl){ Rubicure::Girl.find(girl_name) }
let(:girl_name){ :peace }

context "same series" do
it { expect(series === series).to be true }
it { expect(series === girl).to be true }
end

context "other series" do
let(:other_series){ Rubicure::Series.find(:dokidoki) }
let(:other_girl){ Rubicure::Girl.find(:passion) }
it { expect(series === other_series).to be false }
it { expect(series === other_girl).to be false }
end

context "other ruby object" do
it { expect(series === Module).to be false }
it { expect(series === Object.new).to be false }
it { expect(series === :smile).to be false }
it { expect(series === true).to be false }
it { expect(series === nil).to be false }
end
end

describe "#names" do
subject{ Rubicure::Series.names }

Expand Down

0 comments on commit 2e4ae0e

Please sign in to comment.