Class: ArgentineHolidays
- Inherits:
-
Object
- Object
- ArgentineHolidays
- Defined in:
- lib/argentine_holidays.rb
Overview
require ‘date’
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
10 11 12 13 14 15 |
# File 'lib/argentine_holidays.rb', line 10 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
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 |
# File 'lib/argentine_holidays.rb', line 16 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[0].text, year) } # Movable tables[1].css('tr')[1..-1].each {|i| @@dates += parse_date(i.children[2].text, year) } @@dates.sort! end return @@dates.select {|i| i.year == year } end |