rubicure 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ module Rubicure
2
+ class Series < Hash
3
+ include Hashie::Extensions::MethodAccess
4
+
5
+ @@cache = {}
6
+ @@config = nil
7
+
8
+ # @param [Time,Date,String] arg Time, Date or date like String (ex. "2013-12-16")
9
+ def on_air?(arg)
10
+ date = to_date(arg)
11
+ if respond_to?(:started_date)
12
+ if respond_to?(:ended_date)
13
+ # ended title
14
+ return (started_date .. ended_date).cover?(date)
15
+ else
16
+ # on air title
17
+ return started_date <= date
18
+ end
19
+ end
20
+
21
+ false
22
+ end
23
+
24
+ # @return [Array<Rubicure::Girl>]
25
+ def girls
26
+ unless @girls
27
+ @girls = []
28
+ if has_key?(:girls)
29
+ fetch(:girls).each do |girl_name|
30
+ @girls << Rubicure::Girl.find(girl_name.to_sym)
31
+ end
32
+ end
33
+ end
34
+
35
+ @girls
36
+ end
37
+
38
+ # @return [Array<Symbol>]
39
+ def self.names
40
+ config.keys
41
+ end
42
+
43
+ # @return [Array<Symbol>]
44
+ def self.uniq_names
45
+ uniq_names = []
46
+ config.each do |name, series|
47
+ uniq_names << name unless uniq_names.any?{|uniq_name| config[uniq_name][:title] == series[:title] }
48
+ end
49
+ uniq_names
50
+ end
51
+
52
+ # @return [Hash] content of config/series.yml
53
+ def self.config
54
+ unless @@config
55
+ config_file = "#{File.dirname(__FILE__)}/../../config/series.yml"
56
+ @@config = YAML.load_file(config_file).deep_symbolize_keys
57
+ end
58
+ @@config
59
+ end
60
+
61
+ # @return [Hash] content of config/precure.yml
62
+ def self.reload_config!
63
+ @@cache = {}
64
+ @@config = nil
65
+ config
66
+ end
67
+
68
+ # @param [Symbol] series_name
69
+ def self.valid?(series_name)
70
+ names.include?(series_name)
71
+ end
72
+
73
+ # @param series_name [Symbol]
74
+ # @return [Rubicure::Series]
75
+ # @raise arg is not precure
76
+ def self.find(series_name)
77
+ raise "unknown series: #{series_name}" unless valid?(series_name)
78
+
79
+ unless @@cache[series_name]
80
+ series_config = config[series_name] || {}
81
+ series_config.reject! { |k, v| v.nil? }
82
+
83
+ @@cache[series_name] = Rubicure::Series[series_config]
84
+ end
85
+
86
+ @@cache[series_name]
87
+ end
88
+
89
+ private
90
+ # @param arg
91
+ # @return [Date] arg is String or Date
92
+ # @return [Time] arg is Time
93
+ # @return [nil] arg is other
94
+ def to_date(arg)
95
+ case arg
96
+ when Date, Time
97
+ arg
98
+ when String
99
+ Date.parse(arg)
100
+ else
101
+ nil
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,3 @@
1
+ module Rubicure
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rubicure.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "active_support/core_ext"
2
+ require 'yaml'
3
+ require 'hashie'
4
+ require "rubicure/version"
5
+ require "rubicure/series"
6
+ require "rubicure/girl"
7
+ require "rubicure/core"
8
+
9
+ module Rubicure
10
+ def self.core
11
+ Rubicure::Core.instance
12
+ end
13
+ end
14
+
15
+ module Precure
16
+ def self.method_missing(name, *args)
17
+ Rubicure.core.send(name, *args)
18
+ end
19
+ end
20
+
21
+ module Cure
22
+ def self.method_missing(name, *args)
23
+ if Rubicure::Girl.valid?(name)
24
+ Rubicure::Girl.find(name)
25
+ else
26
+ super
27
+ end
28
+ end
29
+ end
30
+
31
+ module Shiny
32
+ def self.luminous
33
+ Rubicure::Girl.find(:luminous)
34
+ end
35
+ end
36
+
37
+ module Milky
38
+ def self.rose
39
+ Rubicure::Girl.find(:rose)
40
+ end
41
+ end
data/rubicure.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubicure/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubicure"
8
+ spec.version = Rubicure::VERSION
9
+ spec.authors = ["sue445"]
10
+ spec.email = ["sue445@sue445.net"]
11
+ spec.description = %q{All about Japanese battle heroine "Pretty Cure (Precure)".}
12
+ spec.summary = %q{All about Japanese battle heroine "Pretty Cure (Precure)".}
13
+ spec.homepage = "https://github.com/sue445/rubicure"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = '>= 2.0.0'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "activesupport", "~> 4.0.1"
24
+ spec.add_dependency "hashie", "~> 2.0.5"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta1"
29
+ #spec.add_development_dependency "rspec-parameterized"
30
+ spec.add_development_dependency "delorean"
31
+ spec.add_development_dependency "yard"
32
+ spec.add_development_dependency "codeclimate-test-reporter"
33
+ spec.add_development_dependency "coveralls"
34
+ end
data/spec/core_spec.rb ADDED
@@ -0,0 +1,47 @@
1
+ describe Rubicure::Core do
2
+ let(:instance){ Rubicure::Core.instance }
3
+
4
+ describe "#now" do
5
+ subject{ instance.now }
6
+
7
+ context "when on air" do
8
+ before do
9
+ time_travel_to "2013-01-01"
10
+ end
11
+
12
+ it{ expect(subject.title).to eq "スマイルプリキュア!" }
13
+ end
14
+
15
+ context "when not on air" do
16
+ before do
17
+ time_travel_to "2013-02-01"
18
+ end
19
+
20
+ it{ expect{ subject.title }.to raise_error }
21
+ end
22
+ end
23
+
24
+ it "output all precure methods", category: :verbose do
25
+ Rubicure::Series.names.each do |series_name|
26
+ puts "[#{series_name}] ===================="
27
+ series = Rubicure::Series.find(series_name)
28
+ puts <<EOS
29
+ title: #{series.title}
30
+ broadcast: #{series.started_date} - #{series.ended_date}
31
+ girls: #{series.girls.count}
32
+ EOS
33
+
34
+ series.girls.each do |girl|
35
+ puts <<EOS
36
+ ------------------------
37
+ human_name: #{girl.human_name}
38
+ precure_name: #{girl.precure_name}
39
+ extra_names: #{girl.extra_names}
40
+ state_names: #{girl.state_names}
41
+ transform_message:
42
+ #{girl.transform_message}
43
+ EOS
44
+ end
45
+ end
46
+ end
47
+ end
data/spec/girl_spec.rb ADDED
@@ -0,0 +1,83 @@
1
+ describe Rubicure::Girl do
2
+ describe "#name" do
3
+ let(:girl){
4
+ Rubicure::Girl.new(
5
+ human_name: human_name,
6
+ precure_name: precure_name,
7
+ extra_names: extra_names,
8
+ transform_message: transform_message
9
+ )
10
+ }
11
+
12
+ let(:human_name) { "黄瀬やよい" }
13
+ let(:precure_name) { "キュアピース" }
14
+ let(:extra_names) { %w(プリンセスピース ウルトラピース) }
15
+ let(:transform_message){
16
+ <<EOF
17
+ プリキュアスマイルチャージ!
18
+ GO! GO! Let's GO ピース!
19
+ ピカピカピカリンジャンケンポン! キュアピース!
20
+ EOF
21
+ }
22
+
23
+ context "when before transform" do
24
+ it{ expect(girl.name).to eq human_name }
25
+ end
26
+
27
+ context "when after 1st transform" do
28
+ before do
29
+ girl.transform!
30
+ end
31
+
32
+ it{ expect(girl.name).to eq precure_name }
33
+ end
34
+
35
+ context "when after 2nd transform" do
36
+ before do
37
+ girl.transform!
38
+ girl.transform!
39
+ end
40
+
41
+ it{ expect(girl.name).to eq extra_names[0] }
42
+ end
43
+
44
+ context "when after 3nd transform" do
45
+ before do
46
+ girl.transform!
47
+ girl.transform!
48
+ girl.transform!
49
+ end
50
+
51
+ it{ expect(girl.name).to eq extra_names[1] }
52
+ end
53
+
54
+ context "when after final transform" do
55
+ before do
56
+ girl.transform!
57
+ girl.transform!
58
+ girl.transform!
59
+ girl.transform!
60
+ end
61
+
62
+ # return to human
63
+ it{ expect(girl.name).to eq human_name }
64
+ end
65
+ end
66
+
67
+ describe "#find" do
68
+ subject{ Rubicure::Girl.find(girl_name) }
69
+
70
+ let(:girl_name){ :peace }
71
+
72
+ it{ should be_an_instance_of Rubicure::Girl }
73
+ it{ expect(subject.precure_name).to eq "キュアピース" }
74
+ end
75
+
76
+ describe "#uniq_names" do
77
+ subject{ Rubicure::Girl.uniq_names }
78
+
79
+ let(:all_stars_count){ Rubicure.core.all_stars.count }
80
+
81
+ it{ expect(subject.count).to eq all_stars_count }
82
+ end
83
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubicure do
4
+ it 'should have a version number' do
5
+ expect(Rubicure::VERSION).not_to be_nil
6
+ end
7
+
8
+ describe "Precure." do
9
+ context "When Precure.#<title>" do
10
+ where(:title) do
11
+ [
12
+ [:unmarked],
13
+ [:futari_wa_pretty_cure],
14
+
15
+ [:max_heart],
16
+ [:futari_wa_pretty_cure_max_heart],
17
+
18
+ [:splash_star],
19
+ [:futari_wa_pretty_cure_splash_star],
20
+
21
+ [:yes],
22
+ [:yes_precure_five],
23
+ [:yes_precure5],
24
+
25
+ [:yes_gogo],
26
+ [:yes_precure_five_gogo],
27
+ [:yes_precure5_gogo],
28
+
29
+ [:flesh],
30
+ [:flesh_precure],
31
+
32
+ [:heart_catch],
33
+ [:heart_catch_precure],
34
+
35
+ [:suite],
36
+ [:suite_precure],
37
+
38
+ [:smile],
39
+ [:smile_precure],
40
+
41
+ [:dokidoki],
42
+ [:dokidoki_precure],
43
+
44
+ #[:happiness_charge],
45
+ #[:happiness_charge_precure],
46
+ ]
47
+ end
48
+
49
+ with_them do
50
+ it{ expect{ Precure.send(title) }.not_to raise_error }
51
+ it{ expect{ Precure.send(title).girls }.not_to raise_error }
52
+ end
53
+ end
54
+
55
+ context "When Precure#<unmarked_precure_method>" do
56
+ let(:futari_wa_pretty_cure){ Rubicure::Series.find(:unmarked) }
57
+
58
+ it{ expect(Precure.title).to eq futari_wa_pretty_cure.title }
59
+ it{ expect(Precure.girls.count).to eq futari_wa_pretty_cure.girls.count }
60
+ end
61
+ end
62
+
63
+ describe "Cure." do
64
+ where(:name) do
65
+ [
66
+ [:black],
67
+ [:white],
68
+
69
+ [:bloom],
70
+ [:egret],
71
+
72
+ [:dream],
73
+ [:rouge],
74
+ [:lemonade],
75
+ [:mint],
76
+ [:aqua],
77
+
78
+ [:peach],
79
+ [:berry],
80
+ [:pine],
81
+ [:passion],
82
+
83
+ [:melody],
84
+ [:rhythm],
85
+ [:beat],
86
+ [:muse],
87
+
88
+ [:happy],
89
+ [:sunny],
90
+ [:peace],
91
+ [:march],
92
+ [:beauty],
93
+
94
+ [:heart],
95
+ [:diamond],
96
+ [:rosetta],
97
+ [:sword],
98
+ [:ace],
99
+ ]
100
+ end
101
+
102
+ with_them do
103
+ it{ expect( Cure.send(name) ).to be_an_instance_of Rubicure::Girl }
104
+ it{ expect( Cure.send(name).precure_name ).to be_start_with "キュア" }
105
+ end
106
+
107
+ context "When precure who not starting 'cure'" do
108
+ it{ expect( Shiny.luminous.precure_name ).to eq "シャイニールミナス"}
109
+ it{ expect( Milky.rose.precure_name ).to eq "ミルキィローズ"}
110
+ end
111
+ end
112
+
113
+ describe "#all_stars" do
114
+ subject{ Precure.all_stars }
115
+
116
+ before do
117
+ @precure_count = 0
118
+ config_file = "#{File.dirname(__FILE__)}/../config/girls.yml"
119
+ Pathname(config_file).each_line do |line|
120
+ @precure_count += 1 if line =~ /[a-z_]+:\s*&[a-z_]+/
121
+ end
122
+ end
123
+
124
+ it{ expect(subject.count).to eq @precure_count }
125
+ end
126
+ end
@@ -0,0 +1,101 @@
1
+ describe Rubicure::Series do
2
+ describe "#on_air?" do
3
+ subject{ series.on_air?(date) }
4
+
5
+ context "when ended title" do
6
+ let(:series) {
7
+ Rubicure::Series[
8
+ started_date: Date.parse("2012-02-05"),
9
+ ended_date: Date.parse("2013-01-27"),
10
+ ]
11
+ }
12
+
13
+ context "when Date arg" do
14
+ let(:date){ Date.parse("2013-01-01") }
15
+
16
+ it{ should be true }
17
+ end
18
+
19
+ context "when date like String arg" do
20
+ let(:date){ "2013-01-01" }
21
+
22
+ it{ should be true }
23
+ end
24
+ end
25
+
26
+ context "when live title" do
27
+ let(:series) {
28
+ Rubicure::Series[
29
+ started_date: Date.parse("2013-02-03"),
30
+ ]
31
+ }
32
+
33
+ let(:date){ Date.parse("2013-12-01") }
34
+
35
+ it{ should be true }
36
+ end
37
+ end
38
+
39
+ describe "#girls" do
40
+ subject{ series.girls }
41
+
42
+ let(:series) {
43
+ Rubicure::Series[
44
+ girls: %w(cure_happy cure_sunny cure_peace cure_march cure_beauty)
45
+ ]
46
+ }
47
+
48
+ it'has 5 girls' do
49
+ expect(subject.size).to eq(5)
50
+ end
51
+
52
+ it{ should array_instance_of Rubicure::Girl }
53
+ end
54
+
55
+ let(:series_names) {
56
+ [
57
+ :unmarked,
58
+ :max_heart,
59
+ :splash_star,
60
+ :yes,
61
+ :yes_gogo,
62
+ :flesh,
63
+ :heart_catch,
64
+ :suite,
65
+ :smile,
66
+ :dokidoki,
67
+ #:happiness_charge,
68
+ ]
69
+ }
70
+
71
+ describe "#names" do
72
+ subject{ Rubicure::Series.names }
73
+
74
+ it{ should include *series_names }
75
+ end
76
+
77
+ describe "#uniq_names" do
78
+ subject{ Rubicure::Series.uniq_names }
79
+
80
+ it{ should include *series_names }
81
+ it{ expect(subject.count).to eq series_names.count }
82
+ end
83
+
84
+ describe "#find" do
85
+ subject(:series){ Rubicure::Series.find(series_name) }
86
+
87
+ context "when exists" do
88
+ let(:series_name){ :smile }
89
+
90
+ it{ expect(series.title).to eq "スマイルプリキュア!" }
91
+ it{ expect(series.girls.count).to eq 5 }
92
+ end
93
+
94
+ context "when not exists" do
95
+ let(:series_name){ :ashita_no_nadja }
96
+
97
+ it{ expect{subject}.to raise_error }
98
+ end
99
+ end
100
+
101
+ end
@@ -0,0 +1,23 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
+ require 'rubicure'
9
+ require 'rspec'
10
+ require 'rspec-parameterized'
11
+ require 'delorean'
12
+
13
+ # Requires supporting ruby files with custom matchers and macros, etc,
14
+ # in spec/support/ and its subdirectories.
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ RSpec.configure do |config|
18
+ config.include Delorean
19
+
20
+ config.after(:each) do
21
+ back_to_the_present
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ require "rspec"
2
+
3
+ =begin
4
+ example)
5
+ [1, 2, 3].should array_instance_of Fixnum
6
+ =end
7
+
8
+ RSpec::Matchers.define :array_instance_of do |element_class|
9
+ match do |array|
10
+ array.class == Array && array.all? {|element| element.class == element_class}
11
+ end
12
+ end