Skip to content

Commit

Permalink
Merge 7595578 into 1916063
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Aug 22, 2014
2 parents 1916063 + 7595578 commit 83f6de5
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 104 deletions.
13 changes: 7 additions & 6 deletions lib/rubicure/concerns/util.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module Rubicure
module Concerns
# utility methods
module Util
# @param arg
# @return [Date] arg is String or Date
# @return [Time] arg is Time
# @return [nil] arg is other
def to_date(arg)
case arg
when Date, Time
arg
when String
Date.parse(arg)
else
nil
when Date, Time
arg
when String
Date.parse(arg)
else
nil
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions lib/rubicure/core.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Rubicure
require "singleton"

# generic methods
class Core
include Singleton
include Enumerable
Expand Down Expand Up @@ -32,14 +33,14 @@ def now

# @param [Time,Date,String,Symbol] arg Time, Date or date like String (ex. "2013-12-16")
# @return [Array<Rubicure::Girl>]
def all_stars(arg=Time.current)
def all_stars(arg = Time.current)
unless @all_stars
@all_stars = []
Rubicure::Girl.names.each do |girl_name|
@all_stars << Rubicure::Girl.find(girl_name)
end

@all_stars.uniq!{|girl| girl.human_name }
@all_stars.uniq! { |girl| girl.human_name }
end

begin
Expand All @@ -50,7 +51,7 @@ def all_stars(arg=Time.current)
date = to_date(arg)
end

@all_stars.select{|girl| girl.created_date && girl.created_date <= date }
@all_stars.select { |girl| girl.created_date && girl.created_date <= date }
end

# iterate with :unmarked, :max_heart, ...
Expand Down
7 changes: 5 additions & 2 deletions lib/rubicure/girl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module Rubicure
# Precure girl (ex. Cure Peace, Cure Rosetta, Cure Honey)
#
# this is record of "config/girls.yml"
class Girl
attr_reader :human_name, :precure_name, :transform_message, :extra_names, :current_state, :state_names, :created_date

Expand All @@ -16,7 +19,7 @@ def initialize(human_name: nil, precure_name: nil, transform_message: nil, extra
@state_names += @extra_names unless @extra_names.empty?
end

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

Expand Down Expand Up @@ -62,7 +65,7 @@ def self.names
def self.uniq_names
uniq_names = []
config.each do |name, series|
uniq_names << name unless uniq_names.any?{|uniq_name| config[uniq_name][:precure_name] == series[:precure_name] }
uniq_names << name unless uniq_names.any? { |uniq_name| config[uniq_name][:precure_name] == series[:precure_name] }
end
uniq_names
end
Expand Down
5 changes: 4 additions & 1 deletion lib/rubicure/movie.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module Rubicure
# Precure All Stars Movie
#
# this is record of "config/movies.yml"
class Movie < Hash
include Hashie::Extensions::MethodAccess

Expand All @@ -14,7 +17,7 @@ def self.names
def self.uniq_names
uniq_names = []
config.each do |name, series|
uniq_names << name unless uniq_names.any?{|uniq_name| config[uniq_name][:title] == series[:title] }
uniq_names << name unless uniq_names.any? { |uniq_name| config[uniq_name][:title] == series[:title] }
end
uniq_names
end
Expand Down
6 changes: 4 additions & 2 deletions lib/rubicure/series.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module Rubicure
# Precure TV series (ex. Smile Precure, Dokidoki Orecure)
# this is record of "config/series.yml"
class Series < Hash
include Hashie::Extensions::MethodAccess
include Rubicure::Concerns::Util
Expand All @@ -8,7 +10,7 @@ class Series < Hash

# @param [Rubicure::Series,Rubicure::Girl] other
# @return [Boolean] other is same Rubicure::Series or Rubicure::Series include Rubicure::Girl
def === (other)
def ===(other)
case other
when self.class
self == other
Expand Down Expand Up @@ -58,7 +60,7 @@ def self.names
def self.uniq_names
uniq_names = []
config.each do |name, series|
uniq_names << name unless uniq_names.any?{|uniq_name| config[uniq_name][:title] == series[:title] }
uniq_names << name unless uniq_names.any? { |uniq_name| config[uniq_name][:title] == series[:title] }
end
uniq_names
end
Expand Down
12 changes: 6 additions & 6 deletions spec/core_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe Rubicure::Core do
let(:instance){ Rubicure::Core.instance }
let(:instance) { Rubicure::Core.instance }

describe "#now" do
subject{ instance.now }
Expand All @@ -9,15 +9,15 @@
time_travel_to "2013-01-01"
end

its(:title){ should == "スマイルプリキュア!" }
its(:title) { should == "スマイルプリキュア!" }
end

context "when not on air" do
before do
time_travel_to "2013-02-01"
end

it{ expect{ subject }.to raise_error }
it { expect { subject }.to raise_error }
end
end

Expand Down Expand Up @@ -52,7 +52,7 @@
end
end

it{ expect{|b| instance.each_with_series(&b) }.to yield_successive_args *@expected_series }
it { expect { |b| instance.each_with_series(&b) }.to yield_successive_args *@expected_series }
end

describe "#all_stars" do
Expand All @@ -68,7 +68,7 @@
@precure_count = human_names.uniq.count
end

its(:count){ should == @precure_count }
its(:count) { should == @precure_count }
end

context "With arg" do
Expand All @@ -95,7 +95,7 @@
end

with_them do
its(:count){ should == expected_count }
its(:count) { should == expected_count }
end
end
end
Expand Down
48 changes: 24 additions & 24 deletions spec/girl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
describe Rubicure::Girl do
let(:girl){
let(:girl) do
Rubicure::Girl.new(
human_name: human_name,
precure_name: precure_name,
extra_names: extra_names,
transform_message: transform_message
)
}
end

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

describe "#name" do
context "when before transform" do
it{ expect(girl.name).to eq human_name }
it { expect(girl.name).to eq human_name }
end

context "when after 1st transform" do
before do
girl.transform!
end

it{ expect(girl.name).to eq precure_name }
it { expect(girl.name).to eq precure_name }
end

context "when after 2nd transform" do
Expand All @@ -38,7 +38,7 @@
girl.transform!
end

it{ expect(girl.name).to eq extra_names[0] }
it { expect(girl.name).to eq extra_names[0] }
end

context "when after 3nd transform" do
Expand All @@ -48,7 +48,7 @@
girl.transform!
end

it{ expect(girl.name).to eq extra_names[1] }
it { expect(girl.name).to eq extra_names[1] }
end

context "when after final transform" do
Expand All @@ -60,51 +60,51 @@
end

# return to human
it{ expect(girl.name).to eq human_name }
it { expect(girl.name).to eq human_name }
end
end

describe "#==" do
subject{ girl == other_girl }

context "same object" do
let(:other_girl){ girl }
it{ should be true }
let(:other_girl) { girl }
it { should be true }
end

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

context "precure and human" do
let(:transformed_girl){ girl.dup.transform! }
let(:other_girl){ transformed_girl }
let(:transformed_girl) { girl.dup.transform! }
let(:other_girl) { transformed_girl }

it{ expect(girl.name).not_to eq transformed_girl.name }
it{ should be true }
it { expect(girl.name).not_to eq transformed_girl.name }
it { should be true }
end

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

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

let(:girl_name){ :peace }
let(:girl_name) { :peace }

it{ should be_an_instance_of Rubicure::Girl }
its(:precure_name){ should == "キュアピース" }
it { should be_an_instance_of Rubicure::Girl }
its(:precure_name) { should == "キュアピース" }
end

describe "#uniq_names" do
subject{ Rubicure::Girl.uniq_names }

let(:containing_name_alias_count){ Rubicure::Girl.names.count }
let(:containing_name_alias_count) { Rubicure::Girl.names.count }

its(:count){ should < containing_name_alias_count }
its(:count) { should < containing_name_alias_count }
end
end
18 changes: 9 additions & 9 deletions spec/movie_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe Rubicure::Movie do
let(:movie_names) {
let(:movie_names) do
[
:dx1,
:dx2,
Expand All @@ -8,34 +8,34 @@
:ns2,
:ns3,
]
}
end

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

it{ should include *movie_names }
it { should include *movie_names }
end

describe "#uniq_names" do
subject{ Rubicure::Movie.uniq_names }

it{ should include *movie_names }
its(:count){ should == movie_names.count }
it { should include *movie_names }
its(:count) { should == movie_names.count }
end

describe "#find" do
subject{ Rubicure::Movie.find(movie_name) }

context "when exists" do
let(:movie_name){ :dx }
let(:movie_name) { :dx }

its(:title){ should == "映画 プリキュアオールスターズDX みんなともだちっ☆奇跡の全員大集合!" }
its(:title) { should == "映画 プリキュアオールスターズDX みんなともだちっ☆奇跡の全員大集合!" }
end

context "when not exists" do
let(:movie_name){ :ashita_no_nadja }
let(:movie_name) { :ashita_no_nadja }

it{ expect{subject}.to raise_error }
it { expect{ subject }.to raise_error }
end
end

Expand Down
Loading

0 comments on commit 83f6de5

Please sign in to comment.