Class: Renalware::Age
- Inherits:
-
NestedAttribute
- Object
- Document::Embedded
- NestedAttribute
- Renalware::Age
- Defined in:
- app/documents/renalware/age.rb
Constant Summary collapse
- AGE_IN_MONTHS_THRESHOLD =
If below this number of years, age must be in months
3
Constants inherited from Document::Embedded
Document::Embedded::STRIPPABLE_TYPES
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from NestedAttribute
#nested_attribute?, #to_partial_path
Methods inherited from Document::Embedded
attribute, attributes_list, #method_missing, old_attribute, old_attributes, #strip_leading_trailing_whitespace_from_numbers
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Document::Embedded
Class Method Details
.age_in_months_threshold ⇒ Object
15 16 17 |
# File 'app/documents/renalware/age.rb', line 15 def self.age_in_months_threshold AGE_IN_MONTHS_THRESHOLD end |
.new_from(years:, months:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/documents/renalware/age.rb', line 19 def self.new_from(years:, months:, **) new.tap do |age| if years && months if years < age_in_months_threshold age.amount = years * 12 + months age.unit = :months else age.amount = years age.unit = :years end end end end |
Instance Method Details
#to_s ⇒ Object
33 34 35 |
# File 'app/documents/renalware/age.rb', line 33 def to_s amount.present? ? "#{amount} #{unit.try(:text)}" : "" end |