Class: Renum::NameSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/renum/name_serializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(enum_class) ⇒ NameSerializer

Returns a new instance of NameSerializer.



3
4
5
# File 'lib/renum/name_serializer.rb', line 3

def initialize enum_class
  @enum_class = enum_class
end

Instance Method Details

#dump(v) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/renum/name_serializer.rb', line 7

def dump v
  v && if v.is_a?(String)
         v
       else
         v.name
       end
end

#load(s) ⇒ Object



15
16
17
# File 'lib/renum/name_serializer.rb', line 15

def load s
  s && @enum_class.with_name(s)
end