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



51
52
53
# File 'lib/domain/widget.rb', line 51

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

Instance Method Details

#as_json(options = {}) ⇒ Hash

Converts Widget object to Hash and deletes null value fields

Parameters:

  • options (Refrence) (defaults to: {})

Returns:

  • (Hash)

    Hash of widget object



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

def as_json(options = {})
  hash_data = {
    self.class.name.downcase => {
      name: @name,
      description: @description,
      kind: @kind
    }
  }

  hash_data.each { |k, v| v.delete_if { |k, v| v.nil? || v.empty? } }
  hash_data
end