people_compatible 0.0.2 → 0.0.3

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: 5a783d5447609aefc7156f233fa1c0478b829452
4
- data.tar.gz: f7d9a4b4d911e1d26e99b1a0edd8bf8e953bfb6b
3
+ metadata.gz: 401a551f5f50b0e9142c76fbf824532ab9d595f3
4
+ data.tar.gz: a8fa85b27f17dd546033cfa645ff97564be4498e
5
5
  SHA512:
6
- metadata.gz: 41e8d999cac2e8b921990ca0472f14ceebaddca17ae10d462a665412b9b74b3991a4bfe134f7eb2fda5321e068e9029b656e8e94a84f49915748dd6dee16124e
7
- data.tar.gz: cd5d9080730c5fa1037092b6768f97cfb573e6929f7a4ea9d13f8715ceb1ea91e6cc6554dc0287d0b5a5d84f46a65a871b4a6c1fb7693962c86f663cda44f49b
6
+ metadata.gz: 79e0365b85160cb9c1b90e840bdb318d75d411678be18da521b8ab01c08df5fcda7fc1dfc02d7ba6b741c79eb542ab6785d7b8aabcd0b5f6cf9b400c95c7aadf
7
+ data.tar.gz: c03275b3062fa60d8494a44b614c0834d21abef3c8c5287b077023541aa1c1f8ddee401f0651d356ff1c5a342c522ea2317fcde38e136a2f59c54cf87f3470fc
@@ -3,11 +3,10 @@ require_relative 'people_compatible/person'
3
3
  require_relative 'people_compatible/woman'
4
4
 
5
5
  module PeopleCompatible
6
- women = PeopleCompatible::Woman.new('Oksana', '03-12-2010')
7
- man = PeopleCompatible::Man.new('Petya', '03-12-1990')
6
+ def self.print
7
+ women = PeopleCompatible::Woman.new('Oksana', '03-12-2010')
8
+ man = PeopleCompatible::Man.new('Petya', '03-12-1990')
8
9
 
9
- p man.can_marry? women
10
- end
11
-
12
- # require 'people_compatible'
13
- # PeopleCompatiblesssss
10
+ man.can_marry? women
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'person.rb'
2
+
3
+ module PeopleCompatible
4
+
5
+ class Man < Person
6
+ def avg_life
7
+ 62
8
+ end
9
+
10
+ def can_marry?(person)
11
+ super
12
+
13
+ @can_marry.nil? ? age >= 18 : @can_marry
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,68 @@
1
+ =begin
2
+
3
+ Создать класс Person, который можно проинициализировать таким образом:
4
+
5
+ person = Person.new('Oksana', '03-12-1991')
6
+
7
+ Конструктор принимает 2 параметра: name, birthday в формате, указанном выше.
8
+ Для того, чтоб привести данную строку к дате, используем метод Date.parse(birthday).
9
+
10
+ Задание № 1. Написать метод age, который определяет возраст человека.
11
+
12
+ Задание № 2. Создать классы Woman и Man - наследники класса Person. Для каждого класса
13
+ определить среднюю продолжительность жизни в методе avg_life( Person: 68, Woman: 74, Man: 62).
14
+ Написать метод older_than_avg?, который возвращает true или false в зависимости от того, больше
15
+ ли возраст данного объекта чем средняя продолжительность жизни для этого класса.
16
+
17
+ person.older_than_avg?
18
+
19
+ Задание № 3. Написать метод can_marry?(person), который будет возвращать true или false в
20
+ зависимости от того, может ли данный человек вступить в брак с тем, который передается
21
+ параметром. При этом:
22
+ - мужчина может жениться с 18 лет
23
+ - женщина может выйти замуж с 17 лет
24
+ - однополые браки не разрешены
25
+ - если один из брачующихся - объект класса Person, нужно raise TypeError
26
+
27
+ woman = Woman.new('Alina', '03-12-1990')
28
+ man = Man.new('Ivan', '03-12-1985')
29
+ man.can_marry?(woman) #=> true
30
+ =end
31
+
32
+ require 'date'
33
+
34
+ #TODO здесь должен быть ваш код
35
+
36
+ module PeopleCompatible
37
+ class Person
38
+
39
+ def initialize(name, birthday)
40
+ @name = name
41
+ @birthday = Date.parse(birthday)
42
+ end
43
+
44
+ def age
45
+ ((DateTime.now - @birthday) / 365.25).to_i
46
+ end
47
+
48
+ def avg_life
49
+ 68
50
+ end
51
+
52
+ def older_than_avg?
53
+ age > avg_life
54
+ end
55
+
56
+ def can_marry?(person)
57
+ @can_marry = nil
58
+
59
+ if person.class == Person || self.class == Person
60
+ raise TypeError, 'Объект Person'
61
+ end
62
+
63
+ if person.class == self.class
64
+ @can_marry = false
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module PeopleCompatible
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'person.rb'
2
+
3
+ module PeopleCompatible
4
+ class Woman < Person
5
+ def avg_life
6
+ 74
7
+ end
8
+
9
+ def can_marry?(person)
10
+ super
11
+
12
+ @can_marry.nil? ? age >= 17 : @can_marry
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: people_compatible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Smith
@@ -9,21 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-09-24 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 4.1.6
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 4.1.6
12
+ dependencies: []
27
13
  description: Compatible peoples
28
14
  email: im@demetrodon.com
29
15
  executables: []
@@ -31,6 +17,10 @@ extensions: []
31
17
  extra_rdoc_files: []
32
18
  files:
33
19
  - lib/people_compatible.rb
20
+ - lib/people_compatible/man.rb
21
+ - lib/people_compatible/person.rb
22
+ - lib/people_compatible/version.rb
23
+ - lib/people_compatible/woman.rb
34
24
  homepage: http://demetrodon.com
35
25
  licenses:
36
26
  - MIT