Class: Widget
- Inherits:
-
Object
- Object
- Widget
- Defined in:
- lib/domain/widget.rb
Overview
Widget model conatining widget craeate and update attributes
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.get_payload(widget) ⇒ Json
Gets Json represenatation of widget object.
Instance Method Summary collapse
-
#as_json(options = {}) ⇒ Hash
Converts Widget object to Hash and deletes null value fields.
-
#initialize(name: nil, description: nil, kind: nil) ⇒ Widget
constructor
Inialise the widget model.
Constructor Details
#initialize(name: nil, description: nil, kind: nil) ⇒ Widget
Inialise the widget model
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
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/domain/widget.rb', line 8 def description @description end |
#kind ⇒ Object
Returns the value of attribute kind.
9 10 11 |
# File 'lib/domain/widget.rb', line 9 def kind @kind end |
#name ⇒ Object
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
51 52 53 |
# File 'lib/domain/widget.rb', line 51 def self.get_payload() .as_json.to_json end |
Instance Method Details
#as_json(options = {}) ⇒ Hash
Converts Widget object to Hash and deletes null value fields
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/domain/widget.rb', line 31 def as_json( = {}) 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 |