summaryrefslogtreecommitdiff
path: root/lib/family.rb
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-25 10:00:36 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-25 10:00:36 +1100
commit05fda6c29f0fe4742b7ea6b237ea98f737b68b8b (patch)
tree3fca7845fc80f0d93370d2bdadb647f3f9c65d25 /lib/family.rb
parentd41d881cf8af8cb8b6cb89b87a351585ee46063c (diff)
Document code with YARD
Diffstat (limited to 'lib/family.rb')
-rw-r--r--lib/family.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/family.rb b/lib/family.rb
index 2c1acca..5aec487 100644
--- a/lib/family.rb
+++ b/lib/family.rb
@@ -2,9 +2,16 @@
require_relative 'person'
+# Family class representing a family unit with a mother, father, and children.
class Family
attr_reader :mother, :father, :children
+ # Initializes a new Family object.
+ #
+ # @param mother [Person, NilPerson] The mother of the family, defaults to NilPerson.
+ # @param father [Person, NilPerson] The father of the family, defaults to NilPerson.
+ # @param children [Array<Person>] The children of the family, defaults to an empty array.
+ # @raise [ArgumentError] if the mother is not female or the father is not male.
def initialize(mother = NilPerson.new, father = NilPerson.new, children = [])
raise ArgumentError, 'Mother must be female' if !mother.is_a?(NilPerson) && mother.gender != Gender::FEMALE
raise ArgumentError, 'Father must be male' if !father.is_a?(NilPerson) && father.gender != Gender::MALE
@@ -14,12 +21,22 @@ class Family
@children = children
end
+ # Assigns a new mother to the family.
+ #
+ # @param mother [Person] The new mother.
+ # @raise [ArgumentError] if the mother is not female.
+ # @return [void]
def assign_mother(mother)
raise ArgumentError, 'Mother must be female' if mother.gender != Gender::FEMALE
@mother = mother
end
+ # Assigns a new father to the family.
+ #
+ # @param father [Person] The new father.
+ # @raise [ArgumentError] if the father is not male.
+ # @return [void]
def assign_father(father)
raise ArgumentError, 'Father must be male' if father.gender != Gender::MALE