class ArgentineHolidays
Constants
- MONTHS
Public Class Methods
between(from, to)
click to toggle source
# 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)
click to toggle source
# 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
Private Class Methods
parse_date(date, year)
click to toggle source
# File lib/argentine_holidays.rb, line 43 def self.parse_date(date, year) month = MONTHS.index {|i| /#{i}/ === date } if month month += 1 days = date.scan(/[0-9]{1,2}/) return days.collect {|day| Date.new(year, month, day.to_i)} else return [] end end