Module: MyRepresentatives::Guessable

Instance Method Summary collapse

Instance Method Details

#guess_first(str) ⇒ Object



4
5
6
7
8
9
10
11
12
13
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
45
46
# File 'lib/my_representatives/guessable.rb', line 4

def guess_first(str)
  name = str
  name.gsub!(/\((.+?)\)\s/,"")

  if name

    name = if name.start_with?("Hon ")
      name.gsub("Hon ", "")
    elsif name.start_with?("The Hon. Dr ")
      name.gsub("The Hon. Dr ", "")
    elsif name.start_with?("Reverend the Hon. ")
      name.gsub("Reverend the Hon. ", "")
    elsif name.start_with?("Hon. ")
      name.gsub("Hon. ", "")
    elsif name.start_with?("Senator the Hon ")
      name.gsub("Senator the Hon ", "")
    elsif name.start_with?("The Hon. ")
      name.gsub("The Hon. ", "")
    elsif name.start_with?("The Hon ")
      name.gsub("The Hon ", "")
    elsif name.start_with?("Senator ")
      name.gsub("Senator ", "")
    elsif name.start_with?("Mrs ")
      name.gsub("Mrs ", "")
    elsif name.start_with?("Miss ")
      name.gsub("Miss ", "")
    elsif name.start_with?("Ms ")
      name.gsub("Ms ", "")
    elsif name.start_with?("Mr ")
      name.gsub("Mr ", "")
    elsif name.start_with?("Dr ")
      name.gsub("Dr ", "")
    else
      name
    end

    name = name.split(" ")
    name[0]

  else
    nil
  end
end

#guess_gender(str) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/my_representatives/guessable.rb', line 69

def guess_gender(str)
  if str
    if str == "Mrs"
      "Female"
    elsif str == "Miss"
      "Female"
    elsif str == "Ms"
      "Female"
    elsif str == "Mr"
      "Male"
    else
      nil
    end
  else
    nil
  end
end

#guess_last(str) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/my_representatives/guessable.rb', line 48

def guess_last(str)
  name = str
  if name
    name.gsub(" MLA", "").gsub(" MLC", "").gsub(" MP", "").gsub(" QC", "").gsub(" AO", "").gsub(" AOM", "").gsub(" OAM", "").gsub(" CSC", "").gsub(",","").strip.split(" ").last
  else
    nil
  end
end

#guess_preferred(str) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/my_representatives/guessable.rb', line 56

def guess_preferred(str)
  name = str
  regex = /\((.+?)\)/
  match = name.match(regex)

  if match
    match[1]
  else
    nil
  end

end

#guess_title(str) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/my_representatives/guessable.rb', line 87

def guess_title(str)
  name = str
  if name
    name = if name.start_with?("Hon ")
      "Hon"
    elsif name.start_with?("The Hon")
      "The Hon"
    elsif name.start_with?("Senator the Hon ")
      "Senator the Hon"
    elsif name.start_with?("Senator ")
      "Senator"
    elsif name.start_with?("Mrs ")
      "Mrs"
    elsif name.start_with?("Miss ")
      "Miss"
    elsif name.start_with?("Ms ")
      "Ms"
    elsif name.start_with?("Mr ")
      "Mr"
    elsif name.start_with?("Dr ")
      "Dr"
    else
      ""
    end
    name
  else
    nil
  end
end