Class: Udb::Presence

Inherits:
T::Enum
  • Object
show all
Defined in:
lib/udb/presence.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_yaml(yaml) ⇒ Object



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

#mandatory?Boolean

Returns:

  • (Boolean)


84
# File 'lib/udb/presence.rb', line 84

def mandatory? = (self == Mandatory)

#optional?Boolean

Returns:

  • (Boolean)


87
# File 'lib/udb/presence.rb', line 87

def optional? = (self != Mandatory)

#optional_typeObject



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

#presenceObject



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_sObject



90
# File 'lib/udb/presence.rb', line 90

def to_s = serialize

#to_s_conciseObject



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