Class: Widget

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

Overview

Widget model conatining widget craeate and update attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Inialise the widget model

Parameters:

  • name (String) (defaults to: nil)

    Name of widget

  • description (String) (defaults to: nil)
  • kind (String) (defaults to: nil)

    Kind of widget - hidden/visible



18
19
20
21
22
# File 'lib/domain/widget.rb', line 18

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

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#kindObject

Returns the value of attribute kind.



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

def kind
  @kind
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.get_payload(widget) ⇒ Json

Gets Json represenatation of widget object

Parameters:

  • widget (Object)

    Widget object

Returns:

  • (Json)

    Json represenatation of widget object



48
49
50
# File 'lib/domain/widget.rb', line 48

def self.get_payload(widget)
  widget.to_json
end

Instance Method Details

#to_json(*data) ⇒ <Type>

Converts Widget object to Json object

Parameters:

  • *data (refrence)

    widget object refrence

Returns:

  • (<Type>)

    Json represenatation of widget object



31
32
33
34
35
36
37
38
39
# File 'lib/domain/widget.rb', line 31

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