Class: Mackerel::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ User

Returns a new instance of User.



5
6
7
8
9
# File 'lib/mackerel/user.rb', line 5

def initialize(args = {})
  @id                              = args["id"]
  @screenName                      = args["screenName"]
  @email                           = args["email"]
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



4
5
6
# File 'lib/mackerel/user.rb', line 4

def email
  @email
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/mackerel/user.rb', line 4

def id
  @id
end

#screenNameObject

Returns the value of attribute screenName.



4
5
6
# File 'lib/mackerel/user.rb', line 4

def screenName
  @screenName
end

Instance Method Details

#to_hObject



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

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



19
20
21
# File 'lib/mackerel/user.rb', line 19

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