zodiac 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -28
- data/lib/locales/ja.yml +15 -0
- data/lib/zodiac/version.rb +1 -1
- metadata +21 -20
data/README.md
CHANGED
@@ -4,27 +4,27 @@
|
|
4
4
|
## Installation
|
5
5
|
|
6
6
|
``` bash
|
7
|
-
|
7
|
+
gem install zodiac
|
8
8
|
```
|
9
9
|
|
10
10
|
Or, if you want to extend your rails app, add the following to the `Gemfile`:
|
11
11
|
|
12
12
|
``` ruby
|
13
|
-
|
13
|
+
gem 'zodiac', '>= 0.2'
|
14
14
|
```
|
15
15
|
|
16
|
-
and run `bundle install
|
16
|
+
and run `bundle install`.
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
20
|
### Time/Date/DateTime usage
|
21
21
|
|
22
22
|
``` ruby
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
require 'zodiac'
|
24
|
+
Time.now.zodiac_sign # => "Aries"
|
25
|
+
require 'date'
|
26
|
+
Date.new(2011, 1, 1).zodiac_sign # => "Capricorn"
|
27
|
+
DateTime.new(2011, 4, 30).zodiac_sign # => "Taurus"
|
28
28
|
```
|
29
29
|
|
30
30
|
`#zodiac_sign` returns values using `I18n` with "zodiac.#{sign}" path, so if you want your own translations, you can put them in your locale with keys like `zodiac.aries`, `zodiac.taurus` etc. See examples [here](http://github.com/7even/zodiac/blob/master/lib/locales/en.yml).
|
@@ -32,8 +32,8 @@ and run `bundle install`
|
|
32
32
|
There are also predicate methods which return `true` if the date is matching the specified zodiac sign (and `false` otherwise).
|
33
33
|
|
34
34
|
``` ruby
|
35
|
-
|
36
|
-
|
35
|
+
Date.new(1989, 2, 26).pisces? # => true
|
36
|
+
Time.gm(1978, 7, 12).gemini? # => false
|
37
37
|
```
|
38
38
|
|
39
39
|
### ActiveRecord usage
|
@@ -43,29 +43,29 @@ The first thing you need to do is to add `gem 'zodiac'` to your `Gemfile` as des
|
|
43
43
|
To add zodiac methods to your model you just call a `zodiac_reader` macro in your model passing it the name of the attribute containing the date of birth:
|
44
44
|
|
45
45
|
``` ruby
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
class Person < ActiveRecord::Base
|
47
|
+
zodiac_reader :dob
|
48
|
+
end
|
49
49
|
```
|
50
50
|
|
51
51
|
and then you'll be able to get zodiac sign of your object just by calling `#zodiac_sign` on it:
|
52
52
|
|
53
53
|
``` ruby
|
54
|
-
|
55
|
-
|
54
|
+
@person = Person.first
|
55
|
+
@person.zodiac_sign # => "Taurus"
|
56
56
|
```
|
57
57
|
|
58
58
|
You can also use the predicate methods like `#libra?`
|
59
59
|
|
60
60
|
``` ruby
|
61
|
-
|
62
|
-
|
61
|
+
@person.libra? # => false
|
62
|
+
@person.taurus? # => true
|
63
63
|
```
|
64
64
|
|
65
65
|
If you also need to search for all geminis in your `people` table, you should add an integer field containing a numerical id of the person's zodiac sign to that table. `zodiac` can help you with that - it already includes a generator `zodiac:migration` which creates a migration adding that field to your table (and an index on that field). You should specify the name of your model class as the first argument while calling the generator:
|
66
66
|
|
67
67
|
``` bash
|
68
|
-
|
68
|
+
rails generate zodiac:migration Person
|
69
69
|
```
|
70
70
|
|
71
71
|
(Note that you must call `zodiac_reader` in your model in order for the migration to run correctly - after creating a new field the migration tries to update it for all existing records)
|
@@ -73,8 +73,8 @@ If you also need to search for all geminis in your `people` table, you should ad
|
|
73
73
|
Now `zodiac_reader` macro in your model gives you some scopes to filter objects by a zodiac sign:
|
74
74
|
|
75
75
|
``` ruby
|
76
|
-
|
77
|
-
|
76
|
+
Person.with_zodiac_sign('libra') # returns all libras
|
77
|
+
Person.gemini # all the geminis
|
78
78
|
```
|
79
79
|
|
80
80
|
To keep the consistency of a zodiac sign with the date of birth, `zodiac_reader` also installs a `before_save` filter to your model, which updates the sign field every time you change the date-of-birth attribute.
|
@@ -82,26 +82,28 @@ To keep the consistency of a zodiac sign with the date of birth, `zodiac_reader`
|
|
82
82
|
If you don't like the name of the field containing zodiac sign (by default it's `zodiac_sign_id`), you can customize it, passing the wanted name as an option to `zodiac_reader` in your model and then as the second parameter to the generator:
|
83
83
|
|
84
84
|
``` ruby
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
class Person < ActiveRecord::Base
|
86
|
+
zodiac_reader :dob, :sign_id_attribute => :custom_sign_id
|
87
|
+
end
|
88
88
|
```
|
89
89
|
|
90
90
|
``` bash
|
91
|
-
|
91
|
+
rails generate zodiac:migration Person custom_sign_id
|
92
92
|
```
|
93
93
|
|
94
94
|
## Included locales
|
95
95
|
|
96
|
-
* en
|
97
|
-
* ru
|
98
|
-
* pt-BR (thanks [jeffrydegrande](https://github.com/jeffrydegrande)
|
96
|
+
* en (English)
|
97
|
+
* ru (Russian)
|
98
|
+
* pt-BR (Brazilian Portuguese) - thanks [jeffrydegrande](https://github.com/jeffrydegrande)
|
99
|
+
* ja (Japanese) - thanks [hamakn](https://github.com/hamakn)
|
99
100
|
|
100
101
|
## Changelog
|
101
102
|
|
102
103
|
* 0.1 Initial version with Time/Date/DateTime extension and [:ru, :en] locales
|
103
|
-
* 0.1.1 Added
|
104
|
+
* 0.1.1 Added Brazilian Portuguese locale (thanks [jeffrydegrande](https://github.com/jeffrydegrande))
|
104
105
|
* 0.2 Added ActiveRecord support (scopes, predicate methods and delegating `#zodiac_sign` to date-of-birth attribute)
|
106
|
+
* 0.2.1 Added Japanese locale (thanks [hamakn](https://github.com/hamakn))
|
105
107
|
|
106
108
|
## Roadmap
|
107
109
|
|
data/lib/locales/ja.yml
ADDED
data/lib/zodiac/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zodiac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: funtimes
|
16
|
-
requirement: &
|
16
|
+
requirement: &70313954155060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70313954155060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: i18n
|
27
|
-
requirement: &
|
27
|
+
requirement: &70313954153940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70313954153940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70313954153340 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70313954153340
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70313954152860 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70313954152860
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activerecord
|
60
|
-
requirement: &
|
60
|
+
requirement: &70313954152100 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '3'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70313954152100
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
|
-
requirement: &
|
71
|
+
requirement: &70313954151680 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70313954151680
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: pry
|
82
|
-
requirement: &
|
82
|
+
requirement: &70313954150940 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70313954150940
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: awesome_print
|
93
|
-
requirement: &
|
93
|
+
requirement: &70313954150320 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70313954150320
|
102
102
|
description: Adds methods for getting a zodiac sign from any Date/Time object containing
|
103
103
|
a date of birth, and can also extend ActiveRecord::Base adding some handy instance
|
104
104
|
and class methods (for searching by a given zodiac sign and more).
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/generators/zodiac/migration/templates/migration30.rb.erb
|
118
118
|
- lib/generators/zodiac/migration/templates/migration31.rb.erb
|
119
119
|
- lib/locales/en.yml
|
120
|
+
- lib/locales/ja.yml
|
120
121
|
- lib/locales/pt-BR.yml
|
121
122
|
- lib/locales/ru.yml
|
122
123
|
- lib/zodiac.rb
|
@@ -147,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
148
|
version: '0'
|
148
149
|
segments:
|
149
150
|
- 0
|
150
|
-
hash:
|
151
|
+
hash: 2762809061880016006
|
151
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
153
|
none: false
|
153
154
|
requirements:
|
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
157
|
version: '0'
|
157
158
|
segments:
|
158
159
|
- 0
|
159
|
-
hash:
|
160
|
+
hash: 2762809061880016006
|
160
161
|
requirements: []
|
161
162
|
rubyforge_project:
|
162
163
|
rubygems_version: 1.8.10
|