class MassInvite::Customer

Customer class

Attributes

location[RW]
name[R]
user_id[R]

Public Class Methods

create_from_file(path = nil) click to toggle source
# 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) click to toggle source
# 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
new(user_id, name, location) click to toggle source
# 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

Public Instance Methods

name=(value) click to toggle source
# File lib/mass_invite/customer.rb, line 40
def name=(value)
  unless value.is_a?(String)
    raise ArgumentError, 'Name should be a string value.'
  end

  raise ArgumentError, "Name can't be empty." if value.empty?

  @name = value
end
user_id=(value) click to toggle source
# File lib/mass_invite/customer.rb, line 32
def user_id=(value)
  unless value.is_a?(Integer)
    raise ArgumentError, 'User ID should be an integer value.'
  end

  @user_id = value
end