Class: Mackerel::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/mackerel/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Channel

Returns a new instance of Channel.



4
5
6
7
8
# File 'lib/mackerel/channel.rb', line 4

def initialize(args = {})
  @id                 = args["id"]
  @name               = args["name"]
  @type               = args["type"]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/mackerel/channel.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mackerel/channel.rb', line 3

def name
  @name
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/mackerel/channel.rb', line 3

def type
  @type
end

Instance Method Details

#to_hObject



10
11
12
13
14
15
16
# File 'lib/mackerel/channel.rb', line 10

def to_h
  instance_variables.flat_map do |name|
    respond_to?(name[1..-1]) ? [name[1..-1]] : []
  end.each_with_object({}) do |name, hash|
    hash[name] = public_send(name)
  end.delete_if { |key, val| val == nil }
end

#to_json(options = nil) ⇒ Object



18
19
20
# File 'lib/mackerel/channel.rb', line 18

def to_json(options = nil)
  return to_h.to_json(options)
end