argentine_holidays 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/argentine_holidays.rb +56 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDc1ZjJiYmFlNGEwYmJhNDQwY2U3ZjM2MWIzNzdkMDA2NWQzNTA0Yw==
5
+ data.tar.gz: !binary |-
6
+ ODI0MzVkZjc0YWQ4NGQzZTY2YzM1M2IyNWM1MjFmMDBjMTVjZmVjNQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ M2U2NzExZDQ1M2VmMmE5ODEwYWFhYWQ1YzBjMjZlZTg1YWE0ZDM4NDg4ZjA1
10
+ ODllMGRhZDJkZDhkYTFiYjM5YzkxMzVkZmM2OGRiN2JmOTU0NjgzNTg5NTJi
11
+ YmZiNTQ5OTZhNmNkMWQwOGE2NTBiNDFjZDBkNGM3YzQzNmZjNzE=
12
+ data.tar.gz: !binary |-
13
+ NWEwMDUyZWIyZDhiMjRmYjI5NjEzYWZlNWM4NTdmN2Q5ZjJiYWE1ZDZkN2Rh
14
+ YTcxZmIwZmVkMGVmYzdhZWQ4ODcxYTQxYTZkZTBiNjYxNTdkMGJkZjQzNjgy
15
+ MmVlMmI5ODc5MjEwYzdiNzViYzYzYzMwYzZlZTBkYTc4Yjc0Mzg=
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'date'
5
+ class ArgentineHolidays
6
+ MONTHS = [
7
+ 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
8
+ 'Julio', 'Agosto', 'Setiembre', 'Octubre', 'Noviembre', 'Diciembre'
9
+ ]
10
+ def self.between(from, to)
11
+ (from..to).collect {|i| i.year }.uniq.each do |year|
12
+ fetch(year)
13
+ end
14
+ return @@dates.select {|d| (from..to).include? d }
15
+ end
16
+ def self.fetch(year)
17
+ unless defined? @@dates
18
+ @@dates = []
19
+ end
20
+
21
+ unless @@dates.any? {|i| i.year == year.to_i }
22
+ begin
23
+ doc = Nokogiri::HTML(open("http://www.mininterior.gov.ar/asuntos_politicos_y_alectorales/dinap/feriados/feriados#{year}.php"))
24
+ rescue OpenURI::HTTPError
25
+ return []
26
+ end
27
+ tables = doc.css('div#info table')
28
+
29
+
30
+ # Non-movable
31
+ tables[0].css('tr')[1..-1].each {|i|
32
+ @@dates += parse_date(i.children[0].text, year)
33
+ }
34
+
35
+ # Movable
36
+ tables[1].css('tr')[1..-1].each {|i|
37
+ @@dates += parse_date(i.children[2].text, year)
38
+ }
39
+ @@dates.sort!
40
+ end
41
+
42
+ return @@dates.select {|i| i.year == year }
43
+ end
44
+ private
45
+ def self.parse_date(date, year)
46
+
47
+ month = MONTHS.index {|i| /#{i}/ === date }
48
+ if month
49
+ month += 1
50
+ days = date.scan(/[0-9]{1,2}/)
51
+ return days.collect {|day| Date.new(year, month, day.to_i)}
52
+ else
53
+ return []
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: argentine_holidays
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Romero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.1
27
+ description: A library to fetch argentine holidays from the official source
28
+ email: sildurin@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/argentine_holidays.rb
34
+ homepage: http://rubygems.org/gems/argentine_holidays
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.0.6
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: A library to fetch argentine holidays from the official source
58
+ test_files: []