Class: Switches::Update

Inherits:
Object
  • Object
show all
Includes:
JSONSerializer
Defined in:
lib/switches/update.rb

Constant Summary

Constants included from JSONSerializer

JSONSerializer::ParserError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JSONSerializer

deserialize, serialize, #to_json

Constructor Details

#initialize(attributes = {}) ⇒ Update

Returns a new instance of Update.



20
21
22
23
24
# File 'lib/switches/update.rb', line 20

def initialize(attributes = {})
  @type = attributes["type"]
  @name = attributes["name"]
  @node_id = attributes["node_id"]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/switches/update.rb', line 5

def name
  @name
end

#node_idObject

Returns the value of attribute node_id.



5
6
7
# File 'lib/switches/update.rb', line 5

def node_id
  @node_id
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/switches/update.rb', line 5

def type
  @type
end

Class Method Details

.build(item, node_id) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/switches/update.rb', line 7

def self.build(item, node_id)
  new.tap do |update|
    update.type = item.type
    update.name = item.name
    update.node_id = node_id
  end
end

.load(json) ⇒ Object



15
16
17
18
# File 'lib/switches/update.rb', line 15

def self.load(json)
  attributes = JSONSerializer.deserialize(json)
  new(attributes)
end

Instance Method Details

#as_jsonObject



30
31
32
33
34
35
36
# File 'lib/switches/update.rb', line 30

def as_json
  {
    type: type,
    name: name,
    node_id: node_id
  }
end

#from?(node_id) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/switches/update.rb', line 26

def from?(node_id)
  @node_id == node_id
end