Class: Widget

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/widget.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, description: nil, kind: nil) ⇒ Widget

Returns a new instance of Widget.



7
8
9
10
# File 'lib/domain/widget.rb', line 7

def initialize name: nil, description: nil, kind: nil
 self.name, self.description, self.kind =
 name, description, kind
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/domain/widget.rb', line 4

def description
  @description
end

#kindObject

Returns the value of attribute kind.



5
6
7
# File 'lib/domain/widget.rb', line 5

def kind
  @kind
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/domain/widget.rb', line 3

def name
  @name
end

Class Method Details

.get_payload(widget) ⇒ Object



30
31
32
# File 'lib/domain/widget.rb', line 30

def self.get_payload(widget)
  return widget.to_json
end

.json_create(o) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/domain/widget.rb', line 22

def self.json_create(o)
  b_from_json = new
  b_from_json.name = o['name']
  b_from_json.description = o['description']
  b_from_json.kind = o['kind']
  b_from_json
end

Instance Method Details

#to_json(*a) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/domain/widget.rb', line 12

def to_json(*a)
  hash = { 
    name: @name,
    description: @description,
    kind: @kind
  }
  hash.delete_if { |k, v| v.nil? || v.empty?  }
  hash.to_json(*a)
end