Class: NomesTugas
- Inherits:
-
Object
- Object
- NomesTugas
- Defined in:
- lib/nomes_tugas.rb
Class Method Summary collapse
- .conf ⇒ Object
- .get_boys_remote ⇒ Object
- .get_girls_remote ⇒ Object
- .identify_gender(name) ⇒ Object
- .load_names ⇒ Object
- .root ⇒ Object
- .serialize_names ⇒ Object
Class Method Details
.conf ⇒ Object
13 14 15 |
# File 'lib/nomes_tugas.rb', line 13 def self.conf File.join root, 'conf' end |
.get_boys_remote ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nomes_tugas.rb', line 44 def self.get_boys_remote doc = Nokogiri::HTML(open('http://nomesportugueses.blogspot.pt/p/nomes-masculinos-z.html')) print_boys = false doc.css('ul li a').each do |li| if li.to_s.match("href=\"http:\/\/nomesportugueses.blogspot.pt\/search\/label\/") if li.content == "Óscar" print_boys = false end if print_boys == true @boys << li.content end if li.content == "Percepção dos nomes" print_boys = true end end @boys.uniq! end end |
.get_girls_remote ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nomes_tugas.rb', line 26 def self.get_girls_remote doc = Nokogiri::HTML(open('http://nomesportugueses.blogspot.pt/p/nomes-femininos-z.html')) print_girls = false doc.css('ul li a').each do |li| if li.to_s.match("href=\"http:\/\/nomesportugueses.blogspot.pt\/search\/label\/") if li.content == "Variações de Diogo" print_girls = false end if print_girls == true @girls << li.content end if li.content == "Óscar" print_girls = true end end @girls.uniq! end end |
.identify_gender(name) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nomes_tugas.rb', line 66 def self.identify_gender name #get_boys_remote() #get_girls_remote() #serialize_names() load_names() if @girls.include? name "female" elsif @boys.include? name "male" else "not_sure" end end |
.load_names ⇒ Object
62 63 64 65 |
# File 'lib/nomes_tugas.rb', line 62 def self.load_names @boys = YAML.load_file(File.join(conf, 'boys.yaml')) @girls = YAML.load_file(File.join(conf, 'girls.yaml')) end |
.root ⇒ Object
10 11 12 |
# File 'lib/nomes_tugas.rb', line 10 def self.root File. '../..', __FILE__ end |
.serialize_names ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/nomes_tugas.rb', line 16 def self.serialize_names boys_file = File.new(File.join(conf, 'boys.yaml'), "w") girls_file = File.new(File.join(conf, 'girls.yaml'), "w") get_girls_remote() get_boys_remote() boys_file.write(@boys.to_yaml) girls_file.write(@girls.to_yaml) boys_file.close girls_file.close end |