zodiac 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +12 -0
- data/lib/locales/en.yml +15 -0
- data/lib/locales/ru.yml +15 -0
- data/lib/zodiac.rb +6 -0
- data/lib/zodiac/date.rb +12 -0
- data/lib/zodiac/finder.rb +38 -0
- data/lib/zodiac/version.rb +3 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/zodiac/date_spec.rb +17 -0
- data/spec/zodiac/finder_spec.rb +13 -0
- data/zodiac.gemspec +23 -0
- metadata +103 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
desc 'Fires up the console with preloaded zodiac'
|
6
|
+
task :console do
|
7
|
+
sh 'irb -I ./lib/ -rubygems -r ./lib/zodiac.rb'
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new do |t|
|
11
|
+
t.rspec_opts = '--color --format doc'
|
12
|
+
end
|
data/lib/locales/en.yml
ADDED
data/lib/locales/ru.yml
ADDED
data/lib/zodiac.rb
ADDED
data/lib/zodiac/date.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Zodiac
|
2
|
+
module Date
|
3
|
+
def zodiac_sign
|
4
|
+
raise "#{self} should respond_to #month and #day" unless respond_to?(:month) && respond_to?(:day)
|
5
|
+
Finder.sign_for(:month => self.month, :day => self.day)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
[Time, Date, DateTime].each do |date_class|
|
11
|
+
date_class.send(:include, Zodiac::Date)
|
12
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Zodiac
|
2
|
+
module Finder
|
3
|
+
YEAR = 2011
|
4
|
+
|
5
|
+
def self.date_for(month, day)
|
6
|
+
DateTime.new(YEAR, month, day)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.range_for(month_start, day_start, month_end, day_end)
|
10
|
+
SimpleRange.new(date_for(month_start, day_start), date_for(month_end, day_end))
|
11
|
+
end
|
12
|
+
|
13
|
+
RANGES = {
|
14
|
+
range_for(1, 1, 1, 20) => :capricorn,
|
15
|
+
range_for(1, 21, 2, 19) => :aquarius,
|
16
|
+
range_for(2, 20, 3, 20) => :pisces,
|
17
|
+
range_for(3, 21, 4, 20) => :aries,
|
18
|
+
range_for(4, 21, 5, 21) => :taurus,
|
19
|
+
range_for(5, 22, 6, 21) => :gemini,
|
20
|
+
range_for(6, 22, 7, 22) => :cancer,
|
21
|
+
range_for(7, 23, 8, 21) => :leo,
|
22
|
+
range_for(8, 22, 9, 23) => :virgo,
|
23
|
+
range_for(9, 24, 10, 23) => :libra,
|
24
|
+
range_for(10, 24, 11, 22) => :scorpio,
|
25
|
+
range_for(11, 23, 12, 22) => :sagittarius,
|
26
|
+
range_for(12, 23, 12, 31) => :capricorn
|
27
|
+
}
|
28
|
+
|
29
|
+
def self.sign_for(date)
|
30
|
+
RANGES.each do |range, sign|
|
31
|
+
if range.days.include? date_for(date[:month], date[:day])
|
32
|
+
return I18n.t!("zodiac.#{sign}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
raise ArgumentError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'zodiac'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Zodiac
|
4
|
+
describe Date do
|
5
|
+
%w(Time Date DateTime).each do |date_class|
|
6
|
+
context "included into #{date_class}" do
|
7
|
+
before(:each) do
|
8
|
+
@date = Object.const_get(date_class).new(Finder::YEAR, 9, 27)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'provides #zodiac_sign' do
|
12
|
+
@date.zodiac_sign.should == I18n.t('zodiac.libra')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Zodiac
|
4
|
+
describe Finder do
|
5
|
+
it "generates corect dates" do
|
6
|
+
Finder.date_for(9, 27).should == DateTime.new(Finder::YEAR, 9, 27)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns correct zodiac sign" do
|
10
|
+
Finder.sign_for(:month => 9, :day => 27).should == I18n.t('zodiac.libra')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/zodiac.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "zodiac/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "zodiac"
|
7
|
+
s.version = Zodiac::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Vsevolod Romashov"]
|
10
|
+
s.email = ["7@7vn.ru"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Zodiac sign calculator for any date}
|
13
|
+
s.description = %q{Adds methods for getting a zodiac sign from any Date/Time object containing a date of birth}
|
14
|
+
|
15
|
+
s.add_dependency 'funtimes'
|
16
|
+
s.add_dependency 'i18n'
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zodiac
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.1"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vsevolod Romashov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-16 00:00:00 +04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: funtimes
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: i18n
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Adds methods for getting a zodiac sign from any Date/Time object containing a date of birth
|
50
|
+
email:
|
51
|
+
- 7@7vn.ru
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- Rakefile
|
62
|
+
- lib/locales/en.yml
|
63
|
+
- lib/locales/ru.yml
|
64
|
+
- lib/zodiac.rb
|
65
|
+
- lib/zodiac/date.rb
|
66
|
+
- lib/zodiac/finder.rb
|
67
|
+
- lib/zodiac/version.rb
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/zodiac/date_spec.rb
|
70
|
+
- spec/zodiac/finder_spec.rb
|
71
|
+
- zodiac.gemspec
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: ""
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.6.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Zodiac sign calculator for any date
|
100
|
+
test_files:
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/zodiac/date_spec.rb
|
103
|
+
- spec/zodiac/finder_spec.rb
|