Class: MassInvite::Customer

Inherits:
Object
  • Object
show all
Defined in:
lib/mass_invite/customer.rb

Overview

Customer class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, name, location) ⇒ Customer

Returns a new instance of Customer.



26
27
28
29
30
# File 'lib/mass_invite/customer.rb', line 26

def initialize(user_id, name, location)
  self.user_id = user_id
  self.name = name
  self.location = location
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



24
25
26
# File 'lib/mass_invite/customer.rb', line 24

def location
  @location
end

#nameObject

Returns the value of attribute name.



23
24
25
# File 'lib/mass_invite/customer.rb', line 23

def name
  @name
end

#user_idObject

Returns the value of attribute user_id.



23
24
25
# File 'lib/mass_invite/customer.rb', line 23

def user_id
  @user_id
end

Class Method Details

.create_from_file(path = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mass_invite/customer.rb', line 50

def self.create_from_file(path = nil)
  default_path = File.expand_path('../../../data/customers', __FILE__)
  customers_file =
    if path
      File.open(path)
    else
      File.open(default_path)
    end

  customers_file.each_line.map do |line|
    create_from_json_string(line)
  end
end

.create_from_json_string(line) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/mass_invite/customer.rb', line 64

def self.create_from_json_string(line)
  parsed_line = JSON.parse(line, symbolize_names: true)

  loc = Location.new(parsed_line[:latitude],
                     parsed_line[:longitude])
  Customer.new(parsed_line[:user_id], parsed_line[:name], loc)
end