Class: Udb::Presence
- Inherits:
-
T::Enum
- Object
- T::Enum
- Udb::Presence
- Defined in:
- lib/udb/presence.rb
Constant Summary collapse
- Mandatory =
new("mandatory")
- ExpansionOption =
new("expansion option")
- LocalizedOption =
new("localized option")
- DevelopmentOption =
new("development option")
- TransitoryOption =
new("transitory option")
- Option =
legacy option
new("option")
Class Method Summary collapse
Instance Method Summary collapse
- #mandatory? ⇒ Boolean
- #optional? ⇒ Boolean
- #optional_type ⇒ String?
- #presence ⇒ Object
- #to_s ⇒ String
- #to_s_concise ⇒ String
Class Method Details
.from_yaml(yaml) ⇒ Presence
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/udb/presence.rb', line 24 def self.from_yaml(yaml) if yaml.is_a?(String) if yaml == "mandatory" Mandatory else Option end else if yaml.key?("optional") case yaml.fetch("optional") when "expansion" ExpansionOption when "localized" LocalizedOption when "development" DevelopmentOption when "transitory" TransitoryOption else raise "unexpected" end else raise "unexpected" end end end |
Instance Method Details
#optional_type ⇒ String?
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/udb/presence.rb', line 63 def optional_type case self when ExpansionOption "expansion" when LocalizedOption "localized" when DevelopmentOption "development" when TransitoryOption "transitory" when Option nil when Mandatory Udb.logger.fatal "There is no optional_type for a mandatory presence" raise "unexpected" else T.absurd(self) end end |
#presence ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/udb/presence.rb', line 51 def presence case self when Mandatory "mandatory" when ExpansionOption, LocalizedOption, DevelopmentOption, TransitoryOption, Option "optional" else T.absurd(self) end end |
#to_s ⇒ String
90 |
# File 'lib/udb/presence.rb', line 90 def to_s = serialize |
#to_s_concise ⇒ String
93 94 95 96 97 98 99 |
# File 'lib/udb/presence.rb', line 93 def to_s_concise if self == Mandatory "mandatory" else "optional" end end |