Class: ArgentineHolidays

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

Constant Summary collapse

MONTHS =
[
 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 
 'Julio', 'Agosto', 'Setiembre', 'Octubre', 'Noviembre', 'Diciembre'
]

Class Method Summary collapse

Class Method Details

.between(from, to) ⇒ Object



8
9
10
11
12
13
# File 'lib/argentine_holidays.rb', line 8

def self.between(from, to)
  (from..to).collect {|i| i.year }.uniq.each do |year|
    fetch(year)
  end
  return @@dates.select {|d| (from..to).include? d }
end

.fetch(year) ⇒ Object



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
# File 'lib/argentine_holidays.rb', line 14

def self.fetch(year)
  unless defined? @@dates
    @@dates = [] 
  end

  unless @@dates.any? {|i| i.year == year.to_i }
    begin
      doc = Nokogiri::HTML(open("http://www.mininterior.gov.ar/asuntos_politicos_y_alectorales/dinap/feriados/feriados#{year}.php"))
    rescue OpenURI::HTTPError
      return []
    end
      tables = doc.css('div#info table')
  

    # Non-movable
    tables[0].css('tr')[1..-1].each {|i| 
      @@dates += parse_date(i.children[1].text, year)
    }

    # Movable
    tables[1].css('tr')[1..-1].each {|i| 
      @@dates += parse_date(i.children[3].text, year)
    }
    @@dates.sort!
  end
    
  return @@dates.select {|i| i.year == year }
end