zodiac 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54b14cc9a9d4cc8ce59f0764a494921b943857d9
4
- data.tar.gz: 1dfb4499a9969fba2e555c8c1c2872b5417e1add
3
+ metadata.gz: 164dfe801d088018440c262ddeb47e7468394f60
4
+ data.tar.gz: bdf43d66fc4fa388cf1e5d6091c5cb4dd4133ab2
5
5
  SHA512:
6
- metadata.gz: 2b6cba96f3aa249b5613705320db9aa535ad6d8ef8df2eb745511176a606c9fc3bf369c92b6bcb367d970817160cce55ecac89f1d8b759498da861aa0cc44450
7
- data.tar.gz: 342246bada416a98d2a5821b2b78a977fe8ea0f44030056f2ba1e18460a9b57360dadeac7d2248cae5543046ea314b090ca55e5505b00c599ac94946d80a8a26
6
+ metadata.gz: 2fab9c39c04aea506e35ab7a762ff92a42fb8744e2ed439bf611bd6103bc8995ea02a0d0a433648a3dd6b274d96c32fc9b7a05a3cfeddfa31756a06eb483a05c
7
+ data.tar.gz: a47df25dc5b50ee0c1b6584b389f87a0757c8ceab52c4dd0567ef3d9d6bf28aed19707d0c2e4971f046dc21c41807491d613cd5a1ee88b91eb407fbd44c310bc
@@ -1,4 +1,5 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.0
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # zodiac [![Build Status](https://secure.travis-ci.org/7even/zodiac.png)](http://travis-ci.org/7even/zodiac)
1
+ # zodiac [![Build Status](https://secure.travis-ci.org/7even/zodiac.png)](http://travis-ci.org/7even/zodiac) [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/7even/zodiac)
2
2
 
3
3
  `zodiac` is a simple gem for getting a zodiac sign from a given date of birth. It extends `Time`, `Date` and `DateTime` objects with a `#zodiac_sign` method and can also extend `ActiveRecord::Base` with several instance (delegated to some date attribute of the model object) and class methods (allowing you to search for objects with a certain zodiac sign)
4
4
 
@@ -101,18 +101,22 @@ rails generate zodiac:migration Person custom_sign_id
101
101
  * it (Italian) - thanks [lucapette](https://github.com/lucapette)
102
102
  * es (Spanish) - thanks [jazminschroeder](https://github.com/jazminschroeder)
103
103
  * de (German) - thanks [contradictioned](https://github.com/contradictioned)
104
+ * zh-CN (Chinese) - thanks [lufeihaidao](https://github.com/lufeihaidao)
105
+ * fr (French) - thanks [Belibaste](https://github.com/Belibaste)
106
+ * lv (Latvian) - thanks [ExClouds](https://github.com/ExClouds)
104
107
 
105
108
  ## Changelog
106
109
 
107
- * 0.1 Initial version with Time/Date/DateTime extension and [:ru, :en] locales
108
- * 0.1.1 Added Brazilian Portuguese locale (thanks [jeffrydegrande](https://github.com/jeffrydegrande))
109
- * 0.2 Added ActiveRecord support (scopes, predicate methods and delegating `#zodiac_sign` to date-of-birth attribute)
110
- * 0.2.1 Added Japanese locale (thanks [hamakn](https://github.com/hamakn))
111
- * 0.2.2 Added Italian locale (thanks [lucapette](https://github.com/lucapette))
112
- * 0.2.3 Added Spanish locale (thanks [jazminschroeder](https://github.com/jazminschroeder))
113
- * 0.2.4 Correct leap-year dates handling (thanks [BastienDuplessier](https://github.com/BastienDuplessier))
114
- * 0.2.5 Added German locale (thanks [contradictioned](https://github.com/contradictioned))
115
- * 0.2.6 Added rails 4.0 support (thanks [travisp](https://github.com/travisp))
110
+ * 0.1 Initial version with Time/Date/DateTime extension and [:ru, :en] locales.
111
+ * 0.1.1 Added Brazilian Portuguese locale (thanks [jeffrydegrande](https://github.com/jeffrydegrande)).
112
+ * 0.2 Added ActiveRecord support (scopes, predicate methods and delegating `#zodiac_sign` to date-of-birth attribute).
113
+ * 0.2.1 Added Japanese locale (thanks [hamakn](https://github.com/hamakn)).
114
+ * 0.2.2 Added Italian locale (thanks [lucapette](https://github.com/lucapette)).
115
+ * 0.2.3 Added Spanish locale (thanks [jazminschroeder](https://github.com/jazminschroeder)).
116
+ * 0.2.4 Correct leap-year dates handling (thanks [BastienDuplessier](https://github.com/BastienDuplessier)).
117
+ * 0.2.5 Added German locale (thanks [contradictioned](https://github.com/contradictioned)).
118
+ * 0.2.6 Added rails 4.0 support (thanks [travisp](https://github.com/travisp)).
119
+ * 0.2.7 Added Chinese, French & Latvian locales, added `Zodiac::Date#zodiac_sign_symbol`.
116
120
 
117
121
  ## Roadmap
118
122
 
@@ -0,0 +1,14 @@
1
+ fr:
2
+ zodiac:
3
+ aries: Bélier
4
+ taurus: Taureau
5
+ gemini: Gémeaux
6
+ cancer: Cancer
7
+ leo: Lion
8
+ virgo: Vierge
9
+ libra: Balance
10
+ scorpio: Scorpion
11
+ sagittarius: Sagittaire
12
+ capricorn: Capricorne
13
+ aquarius: Verseau
14
+ pisces: Poisson
@@ -0,0 +1,14 @@
1
+ lv:
2
+ zodiac:
3
+ aries: Auns
4
+ taurus: Vērsis
5
+ gemini: Dvīņi
6
+ cancer: Vēzis
7
+ leo: Lauva
8
+ virgo: Jaunava
9
+ libra: Svari
10
+ scorpio: Skorpions
11
+ sagittarius: Strēlnieks
12
+ capricorn: Mežāzis
13
+ aquarius: Ūdensvīrs
14
+ pisces: Zivis
@@ -0,0 +1,14 @@
1
+ zh-CN:
2
+ zodiac:
3
+ aries: 牡羊座
4
+ taurus: 金牛座
5
+ gemini: 双子座
6
+ cancer: 巨蟹座
7
+ leo: 狮子座
8
+ virgo: 处女座
9
+ libra: 天秤座
10
+ scorpio: 天蝎座
11
+ sagittarius: 射手座
12
+ capricorn: 魔羯座
13
+ aquarius: 水瓶座
14
+ pisces: 双鱼座
@@ -37,7 +37,7 @@ module Zodiac
37
37
  end
38
38
 
39
39
  # Person.by_zodiac(7 || :libra) == Person.where(zodiac_sign_id: 7)
40
- scope :by_zodiac, lambda { |sign|
40
+ scope :by_zodiac, ->(sign) do
41
41
  case sign
42
42
  when Symbol
43
43
  where(self.zodiac_sign_id_field => Zodiac::Finder::SIGN_IDS[sign])
@@ -46,7 +46,7 @@ module Zodiac
46
46
  else
47
47
  raise ArgumentError, "Invalid attribute type #{sign.class} for #{self}.by_zodiac"
48
48
  end
49
- }
49
+ end
50
50
 
51
51
  # Person.gemini == Person.by_zodiac(3)
52
52
  Zodiac.each_sign do |symbol, integer|
@@ -12,6 +12,12 @@ module Zodiac
12
12
  Finder.sign_id_for(month: self.month, day: self.day)
13
13
  end
14
14
 
15
+ def zodiac_sign_symbol
16
+ raise "#{self} should respond_to #month and #day" unless respond_to?(:month) && respond_to?(:day)
17
+
18
+ Finder.sign_symbol_for(month: self.month, day: self.day)
19
+ end
20
+
15
21
  Zodiac.each_sign do |symbol, integer|
16
22
  define_method("#{symbol}?") do # def libra?
17
23
  self.zodiac_sign_id == integer # self.zodiac_sign_id == 7
@@ -21,5 +27,5 @@ module Zodiac
21
27
  end
22
28
 
23
29
  [Time, Date, DateTime].each do |date_class|
24
- date_class.send(:include, Zodiac::Date)
30
+ date_class.send(:include, Zodiac::Date)
25
31
  end
@@ -30,36 +30,38 @@ module Zodiac
30
30
  }
31
31
 
32
32
  SIGN_IDS = {
33
- :aries => 1,
34
- :taurus => 2,
35
- :gemini => 3,
36
- :cancer => 4,
37
- :leo => 5,
38
- :virgo => 6,
39
- :libra => 7,
40
- :scorpio => 8,
41
- :sagittarius => 9,
42
- :capricorn => 10,
43
- :aquarius => 11,
44
- :pisces => 12
33
+ aries: 1,
34
+ taurus: 2,
35
+ gemini: 3,
36
+ cancer: 4,
37
+ leo: 5,
38
+ virgo: 6,
39
+ libra: 7,
40
+ scorpio: 8,
41
+ sagittarius: 9,
42
+ capricorn: 10,
43
+ aquarius: 11,
44
+ pisces: 12
45
45
  }
46
46
 
47
- def self.sign_for(date)
48
- I18n.t!("zodiac.#{self.sign_symbol_for date}")
49
- end
50
-
51
- def self.sign_id_for(date)
52
- SIGN_IDS[self.sign_symbol_for date]
53
- end
54
- private
55
- def self.sign_symbol_for(date)
56
- RANGES.each do |range, sign|
57
- if range.days.cover? date_for(date[:month], date[:day])
58
- return sign
59
- end
47
+ class << self
48
+ def sign_for(date)
49
+ I18n.t!("zodiac.#{self.sign_symbol_for date}")
60
50
  end
61
51
 
62
- raise ArgumentError
52
+ def sign_id_for(date)
53
+ SIGN_IDS[self.sign_symbol_for date]
54
+ end
55
+
56
+ def sign_symbol_for(date)
57
+ RANGES.each do |range, sign|
58
+ if range.days.cover? date_for(date[:month], date[:day])
59
+ return sign
60
+ end
61
+ end
62
+
63
+ raise ArgumentError
64
+ end
63
65
  end
64
66
  end
65
67
  end
@@ -1,3 +1,3 @@
1
1
  module Zodiac
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
@@ -1,10 +1,8 @@
1
- # bootstrap ActiveRecord
2
- require 'active_record'
3
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'spec/support/test.sqlite3')
1
+ require_relative './support/active_record'
4
2
 
5
3
  require 'zodiac'
6
4
  require 'pry'
7
5
 
8
- require File.expand_path('../support/person.rb', __FILE__)
9
- require File.expand_path('../support/lite_person.rb', __FILE__)
10
- require File.expand_path('../support/custom_person.rb', __FILE__)
6
+ require_relative './support/person'
7
+ require_relative './support/lite_person'
8
+ require_relative './support/custom_person'
@@ -0,0 +1,25 @@
1
+ require 'active_record'
2
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
3
+
4
+ ActiveRecord::Migration.create_table :lite_people do |t|
5
+ t.string :name
6
+ t.date :dob
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ ActiveRecord::Migration.create_table :people do |t|
12
+ t.string :name
13
+ t.date :dob
14
+ t.integer :zodiac_sign_id
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ ActiveRecord::Migration.create_table :custom_people do |t|
20
+ t.string :name
21
+ t.date :dob
22
+ t.integer :custom_sign_id
23
+
24
+ t.timestamps
25
+ end
@@ -1,3 +1,3 @@
1
1
  class CustomPerson < ActiveRecord::Base
2
- zodiac_reader :dob, :sign_id_attribute => :custom_sign_id
2
+ zodiac_reader :dob, sign_id_attribute: :custom_sign_id
3
3
  end
@@ -4,10 +4,10 @@ describe Zodiac::ActiveRecord do
4
4
  describe "class methods" do
5
5
  context "standard model" do
6
6
  before(:each) do
7
- @gemini1 = Person.create :dob => Time.gm(1982, 5, 27)
8
- @gemini2 = Person.create :dob => Time.gm(1987, 5, 29)
9
- @libra = Person.create :dob => Time.gm(1984, 9, 27)
10
- @nobody = Person.create :dob => nil
7
+ @gemini1 = Person.create dob: Date.new(1982, 5, 27)
8
+ @gemini2 = Person.create dob: Date.new(1987, 5, 29)
9
+ @libra = Person.create dob: Date.new(1984, 9, 27)
10
+ @nobody = Person.create dob: nil
11
11
  end
12
12
 
13
13
  describe ".zodiac_reader" do
@@ -54,10 +54,10 @@ describe Zodiac::ActiveRecord do
54
54
 
55
55
  context "custom model" do
56
56
  before(:each) do
57
- @gemini1 = CustomPerson.create :dob => Time.gm(1982, 5, 27)
58
- @gemini2 = CustomPerson.create :dob => Time.gm(1987, 5, 29)
59
- @libra = CustomPerson.create :dob => Time.gm(1984, 9, 27)
60
- @nobody = CustomPerson.create :dob => nil
57
+ @gemini1 = CustomPerson.create dob: Date.new(1982, 5, 27)
58
+ @gemini2 = CustomPerson.create dob: Date.new(1987, 5, 29)
59
+ @libra = CustomPerson.create dob: Date.new(1984, 9, 27)
60
+ @nobody = CustomPerson.create dob: nil
61
61
  end
62
62
 
63
63
  describe ".zodiac_reader" do
@@ -88,10 +88,10 @@ describe Zodiac::ActiveRecord do
88
88
 
89
89
  describe "instance_methods" do
90
90
  before(:each) do
91
- dob = Time.gm(1955, 2, 24)
92
- @person = Person.create(:name => 'Steve', :dob => dob)
93
- @lite_person = LitePerson.create(:name => 'Steve lite', :dob => dob)
94
- @nobody = Person.create(:name => 'Nobody', :dob => nil)
91
+ dob = Date.new(1955, 2, 24)
92
+ @person = Person.create(name: 'Steve', dob: dob)
93
+ @lite_person = LitePerson.create(name: 'Steve lite', dob: dob)
94
+ @nobody = Person.create(name: 'Nobody', dob: nil)
95
95
  end
96
96
 
97
97
  describe "#zodiac_sign" do
@@ -145,7 +145,7 @@ describe Zodiac::ActiveRecord do
145
145
 
146
146
  describe "before_save callback" do
147
147
  before(:each) do
148
- @new_dob = Time.gm(1955, 10, 28)
148
+ @new_dob = Date.new(1955, 10, 28)
149
149
  end
150
150
 
151
151
  context "on a migrated model" do
@@ -21,6 +21,10 @@ module Zodiac
21
21
  @date.zodiac_sign_id.should == 7
22
22
  end
23
23
 
24
+ it "provides #zodiac_sign_symbol" do
25
+ @date.zodiac_sign_symbol.should == :libra
26
+ end
27
+
24
28
  Zodiac.each_sign do |symbol, integer|
25
29
  method_name = "#{symbol}?"
26
30
  it "provides ##{method_name}" do
@@ -13,13 +13,19 @@ describe Zodiac::Finder do
13
13
 
14
14
  describe ".sign_for" do
15
15
  it "returns correct zodiac sign" do
16
- subject.sign_for(:month => 9, :day => 27).should == I18n.t('zodiac.libra')
16
+ subject.sign_for(month: 9, day: 27).should == I18n.t('zodiac.libra')
17
17
  end
18
18
  end
19
19
 
20
20
  describe ".sign_id_for" do
21
21
  it "returns correct sign id" do
22
- subject.sign_id_for(:month => 9, :day => 27).should == 7
22
+ subject.sign_id_for(month: 9, day: 27).should == 7
23
+ end
24
+ end
25
+
26
+ describe ".sign_symbol_for" do
27
+ it "returns correct sign symbol" do
28
+ subject.sign_symbol_for(month: 9, day: 27).should == :libra
23
29
  end
24
30
  end
25
31
  end
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zodiac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vsevolod Romashov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2014-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: funtimes
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: awesome_print
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description: Adds methods for getting a zodiac sign from any Date/Time object containing
@@ -131,8 +131,8 @@ executables: []
131
131
  extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
- - .gitignore
135
- - .travis.yml
134
+ - ".gitignore"
135
+ - ".travis.yml"
136
136
  - Gemfile
137
137
  - README.md
138
138
  - Rakefile
@@ -143,20 +143,23 @@ files:
143
143
  - lib/locales/de.yml
144
144
  - lib/locales/en.yml
145
145
  - lib/locales/es.yml
146
+ - lib/locales/fr.yml
146
147
  - lib/locales/it.yml
147
148
  - lib/locales/ja.yml
149
+ - lib/locales/lv.yml
148
150
  - lib/locales/pt-BR.yml
149
151
  - lib/locales/ru.yml
152
+ - lib/locales/zh-CN.yml
150
153
  - lib/zodiac.rb
151
154
  - lib/zodiac/activerecord.rb
152
155
  - lib/zodiac/date.rb
153
156
  - lib/zodiac/finder.rb
154
157
  - lib/zodiac/version.rb
155
158
  - spec/spec_helper.rb
159
+ - spec/support/active_record.rb
156
160
  - spec/support/custom_person.rb
157
161
  - spec/support/lite_person.rb
158
162
  - spec/support/person.rb
159
- - spec/support/test.sqlite3
160
163
  - spec/zodiac/activerecord_spec.rb
161
164
  - spec/zodiac/date_spec.rb
162
165
  - spec/zodiac/finder_spec.rb
@@ -170,26 +173,27 @@ require_paths:
170
173
  - lib
171
174
  required_ruby_version: !ruby/object:Gem::Requirement
172
175
  requirements:
173
- - - '>='
176
+ - - ">="
174
177
  - !ruby/object:Gem::Version
175
178
  version: '0'
176
179
  required_rubygems_version: !ruby/object:Gem::Requirement
177
180
  requirements:
178
- - - '>='
181
+ - - ">="
179
182
  - !ruby/object:Gem::Version
180
183
  version: '0'
181
184
  requirements: []
182
185
  rubyforge_project:
183
- rubygems_version: 2.0.3
186
+ rubygems_version: 2.2.2
184
187
  signing_key:
185
188
  specification_version: 4
186
189
  summary: Zodiac sign calculator for any date
187
190
  test_files:
188
191
  - spec/spec_helper.rb
192
+ - spec/support/active_record.rb
189
193
  - spec/support/custom_person.rb
190
194
  - spec/support/lite_person.rb
191
195
  - spec/support/person.rb
192
- - spec/support/test.sqlite3
193
196
  - spec/zodiac/activerecord_spec.rb
194
197
  - spec/zodiac/date_spec.rb
195
198
  - spec/zodiac/finder_spec.rb
199
+ has_rdoc:
Binary file