Class: Trajectory::Users

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/trajectory/domain/users.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*users) ⇒ Users

Creates a new collection of Trajectory::User

Parameters:



8
9
10
# File 'lib/trajectory/domain/users.rb', line 8

def initialize(*users)
  super(users)
end

Class Method Details

.from_json(json_attributes) ⇒ Object

Create a new collection of Trajectory::User from a JSON array of attributes from trajectory API

Parameters:

  • json_attributes (Hash)

    the hash of attributes of each user of the collection



15
16
17
18
19
# File 'lib/trajectory/domain/users.rb', line 15

def self.from_json(json_attributes)
  new(*json_attributes.map do |attributes|
    User.new(attributes.symbolize_keys!)
  end)
end

Instance Method Details

#find_by_id(id) ⇒ User, false

Returns the the first user with the given id in the collection or false if no user can be found with the id

Parameters:

  • id (Integer)

    the id of the user to find

Returns:

  • (User, false)

    the user with the given id



26
27
28
# File 'lib/trajectory/domain/users.rb', line 26

def find_by_id(id)
  users.find { |user| user.id == id } || false
end