Class: Poms::Builder
- Inherits:
-
Object
show all
- Defined in:
- lib/poms/builder.rb
Overview
Builds the correct object based on the result from POMS.
Defined Under Namespace
Classes: NestedOpenStruct
Constant Summary
collapse
- SUPPORTED_CLASSES =
%w(Broadcast Season Series Views Typeless)
Class Method Summary
collapse
Class Method Details
.poms_class(class_name) ⇒ Object
26
27
28
29
30
|
# File 'lib/poms/builder.rb', line 26
def self.poms_class(class_name)
Poms.const_get class_name
rescue NameError
Poms.const_set class_name, Class.new(Poms::Builder::NestedOpenStruct)
end
|
.pomsify_class_name(class_name) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/poms/builder.rb', line 19
def self.pomsify_class_name(class_name)
class_name = class_name.blank? ? 'Typeless' : class_name.capitalize
class_name =
'Poms' + class_name unless SUPPORTED_CLASSES.include? class_name
class_name
end
|
.process_hash(hash) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/poms/builder.rb', line 9
def self.process_hash(hash)
return unless hash
underscored_hash = hash.each_with_object({}) do |(k, v), res|
res[k.underscore] = v
end
class_name = pomsify_class_name(underscored_hash['type'])
klass = poms_class(class_name)
klass.send(:new, underscored_hash)
end
|