Class: OcrChallenge::IContactInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ocr_challenge/i_contact_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser, list_of_names_dir = 'names') ⇒ IContactInfo

Returns a new instance of IContactInfo.



5
6
7
8
9
10
# File 'lib/ocr_challenge/i_contact_info.rb', line 5

def initialize(parser, list_of_names_dir='names')
  @parser           = parser
  @names            = @parser.parse_names(list_of_names_dir)
  @email_addresses  = @parser.parse_email_addresses
  @phone_numbers    = @parser.parse_phone_numbers
end

Instance Attribute Details

#email_addressesObject (readonly)

Returns the value of attribute email_addresses.



3
4
5
# File 'lib/ocr_challenge/i_contact_info.rb', line 3

def email_addresses
  @email_addresses
end

#namesObject (readonly)

Returns the value of attribute names.



3
4
5
# File 'lib/ocr_challenge/i_contact_info.rb', line 3

def names
  @names
end

#phone_numbersObject (readonly)

Returns the value of attribute phone_numbers.



3
4
5
# File 'lib/ocr_challenge/i_contact_info.rb', line 3

def phone_numbers
  @phone_numbers
end

Instance Method Details

#get_email_addressObject

NOTE: the programming challenge does not account for multiple email addresses, so I take the first one



21
22
23
# File 'lib/ocr_challenge/i_contact_info.rb', line 21

def get_email_address
  "Email: #{email_addresses.first}"
end

#get_nameObject

NOTE: perhaps unlikely, but a business card may have more than one name. For example, maybe there were multiple points of contact for a given company card. Since the challenge did not specify, I take the first one.



15
16
17
# File 'lib/ocr_challenge/i_contact_info.rb', line 15

def get_name
  "Name: #{names.first}"
end

#get_phone_numberObject

NOTE: the programming challenge does not take into account that a contact can have multiple phone numbers, so I take the firs one



27
28
29
# File 'lib/ocr_challenge/i_contact_info.rb', line 27

def get_phone_number
  "Phone: #{phone_numbers.first}"
end

#to_sObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ocr_challenge/i_contact_info.rb', line 31

def to_s
  contact_as_string = ""

  {Name: names, Email: email_addresses,
   "Phone Number" => phone_numbers}.each_pair do |label, values|

    values.each do |value|
      contact_as_string << "#{label}: #{value}\n"
    end
  end

  contact_as_string
end