Class: MyRepresentatives::SA::CSVUpper
- Inherits:
-
Object
- Object
- MyRepresentatives::SA::CSVUpper
- Defined in:
- lib/my_representatives/sa/csv_upper.rb
Instance Attribute Summary collapse
-
#csv_filename ⇒ Object
Returns the value of attribute csv_filename.
-
#csv_url ⇒ Object
Returns the value of attribute csv_url.
-
#people ⇒ Object
Returns the value of attribute people.
Instance Method Summary collapse
- #csv_from_url ⇒ Object
-
#initialize ⇒ CSVUpper
constructor
A new instance of CSVUpper.
- #people_from_csv ⇒ Object
Methods included from Guessable
#guess_first, #guess_gender, #guess_last, #guess_preferred, #guess_title
Methods included from Fileable
Constructor Details
#initialize ⇒ CSVUpper
Returns a new instance of CSVUpper.
9 10 11 12 13 14 15 16 |
# File 'lib/my_representatives/sa/csv_upper.rb', line 9 def initialize @csv_url = "http://www2.parliament.sa.gov.au/Internet/DesktopModules/CreateMM.aspx?type=lc" @csv_filename = "tmp/csv_sa_upper.csv" @people = [] csv_from_url people_from_csv end |
Instance Attribute Details
#csv_filename ⇒ Object
Returns the value of attribute csv_filename.
7 8 9 |
# File 'lib/my_representatives/sa/csv_upper.rb', line 7 def csv_filename @csv_filename end |
#csv_url ⇒ Object
Returns the value of attribute csv_url.
7 8 9 |
# File 'lib/my_representatives/sa/csv_upper.rb', line 7 def csv_url @csv_url end |
#people ⇒ Object
Returns the value of attribute people.
7 8 9 |
# File 'lib/my_representatives/sa/csv_upper.rb', line 7 def people @people end |
Instance Method Details
#csv_from_url ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/my_representatives/sa/csv_upper.rb', line 18 def csv_from_url create_tmp f = open(@csv_url) doc = Nokogiri::HTML(f) CSV.open(@csv_filename, "wb") do |csv| csv << ["title", "first", "last", "address", "city", "state", "postcode"] loops = 0 doc.css("table").css("tr").each do |row| if loops > 0 arr = [] row.css("td").each do |cell| arr << cell.text end csv << arr end loops += 1 end end end |
#people_from_csv ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/my_representatives/sa/csv_upper.rb', line 40 def people_from_csv CSV.foreach(@csv_filename, headers: true) do |row| # Setup the electorate electorate_name = find_electorate electorate = Electorate.new(electorate_name) electorate.state_sa_upper! # Setup the Representative (Person) person = Person.new(electorate) person.title = find_title(row) person.first_name = find_first_name(row) person.last_name = find_last_name(row) person.email = find_email(row) person.phone = find_phone(row) person.party_name = find_party(row) person.gender = guess_gender(person.title) person.formal_name = format_formal_name(person) person.physical_address = format_physical_address(row) person.postal_address = format_postal_address(row) person.honorifics = "MLC" person.preferred_name = nil person.salutation = nil person.image_url = nil person.homepage_url = nil @people << person end end |