Class: CricosScrape::ContactImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/cricos_scrape/importer/contact_importer.rb

Constant Summary collapse

CONTACT_URL =
'http://cricos.education.gov.au/Contacts/CRICOSContacts.aspx'
STATES_CODE =
['ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA']

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ ContactImporter

Returns a new instance of ContactImporter.



10
11
12
# File 'lib/cricos_scrape/importer/contact_importer.rb', line 10

def initialize(agent)
  @agent = agent
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cricos_scrape/importer/contact_importer.rb', line 14

def run
  contacts = []

  for state in STATES_CODE
    @page = agent.get(url_for(state))
    if exist_contacts_of_state?
      @table_contains_contact = @page.at('#ctl00_cphDefaultPage_tabContainer_sheetDetails_cricosContactDetails_pnlContactLists table').children

      number_of_rows_per_contact = 18
      start_contact_row = 3
      end_contact_row = @table_contains_contact.count - number_of_rows_per_contact

      for i in (start_contact_row..end_contact_row).step(number_of_rows_per_contact)
        @row_index = i

        contact                = Contact.new
        contact.type_of_course = find_type_of_course
        contact.name           = find_name
        contact.organisation   = find_organisation
        contact.postal_address = find_postal_address
        contact.telephone      = find_telephone
        contact.facsimile      = find_facsimile
        contact.email          = find_email

        contacts << contact
      end
    end
  end

  contacts
end