Class: IOSGen::Base::BaseFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/ios_gen/base/base_factory.rb

Overview

Create base object from json

Constant Summary collapse

NAME_KEY =
'name'
TYPE_KEY =
'type'
DESCRIPTION_KEY =
'description'
RETURN_KEY =
'return_type'
ARGUMENTS_KEY =
'arguments'
PROPERTIES_KEY =
'properties'
ACTIONS_KEY =
'actions'
INTERACTORS_KEY =
'interactors'

Instance Method Summary collapse

Instance Method Details

#parse_action(hash) ⇒ Object



18
19
20
21
22
23
# File 'lib/ios_gen/base/base_factory.rb', line 18

def parse_action(hash)
  Action.new(description: hash[DESCRIPTION_KEY],
             name: hash[NAME_KEY],
             return_type: hash[RETURN_KEY],
             arguments: parse_properties(hash[ARGUMENTS_KEY]))
end

#parse_actions(actions) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/ios_gen/base/base_factory.rb', line 49

def parse_actions(actions)
  return if actions.nil?
  actions_array = []
  actions.each do |action|
    actions_array.push(parse_action(action))
  end
  actions_array
end

#parse_interactor(hash) ⇒ Object



25
26
27
28
29
30
# File 'lib/ios_gen/base/base_factory.rb', line 25

def parse_interactor(hash)
  Interactor.new(description: hash[DESCRIPTION_KEY],
                 name: hash[NAME_KEY],
                 properties: parse_properties(hash[PROPERTIES_KEY]),
                 actions: parse_actions(hash[ACTIONS_KEY]))
end

#parse_interactors(interactors) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/ios_gen/base/base_factory.rb', line 58

def parse_interactors(interactors)
  return if interactors.nil?
  interactors_array = []
  interactors.each do |interactor|
    interactors_array.push(parse_interactor(interactor))
  end
  interactors_array
end

#parse_properties(arguments) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/ios_gen/base/base_factory.rb', line 40

def parse_properties(arguments)
  return if arguments.nil?
  arguments_properties = []
  arguments.each do |property|
    arguments_properties.push(parse_property(property))
  end
  arguments_properties
end

#parse_property(hash) ⇒ Object



14
15
16
# File 'lib/ios_gen/base/base_factory.rb', line 14

def parse_property(hash)
  Property.new(type: hash[TYPE_KEY], name: hash[NAME_KEY])
end

#parse_view_controller(hash) ⇒ Object



67
68
69
70
# File 'lib/ios_gen/base/base_factory.rb', line 67

def parse_view_controller(hash)
  ViewController.new(name: hash[NAME_KEY],
                     description: hash[DESCRIPTION_KEY])
end

#parse_view_model(hash) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ios_gen/base/base_factory.rb', line 32

def parse_view_model(hash)
  ViewModel.new(description: hash[DESCRIPTION_KEY],
                name: hash[NAME_KEY],
                properties: parse_properties(hash[PROPERTIES_KEY]),
                actions: parse_actions(hash[ACTIONS_KEY]),
                interactors: parse_interactors(hash[INTERACTORS_KEY]))
end