finnish-holidays 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30218b8e1bae7a864a62a2f7d13477e1654b3f49
4
- data.tar.gz: c1e148429bf248bf5c4eec2b15842f09646b3a73
3
+ metadata.gz: 4594700e2e080308f5611414bd6dca073fe03410
4
+ data.tar.gz: 2716b3e7d8b4efaab418c7073bce509efbc4b8e4
5
5
  SHA512:
6
- metadata.gz: 77f13ba900cf0864ebf9c4eebb75fbbafe5e2851c014d41b98b5a1d06d7bdf072e2db5d5b09a1fc565e692d9bf2a745c13a3cedfa02c10a84adc2d0bf137476e
7
- data.tar.gz: ed5fb7cf3f20f26a440cb9857b817fca200081ec4295e05a71a3702321a46fa6e24701070d8e2dfeb9e7e55a5ce71e4b93d24088d508d7b7c0b0aa290199a0d7
6
+ metadata.gz: 17e6e26667a9ad1c485002c2f7752d352c9559316f61925c8da9c935bab93b0453b0153bb5c2a48deb8d15e5a3de8fca234380a5a782095891c340d8ebb2c33a
7
+ data.tar.gz: c0fa21b9efdc03e8729cfa4c3640e774ae58eb6da2ea402fc44870b8d95f8a61332a4ba662d3c692d3e8927ce5eaeebbb230e93e18aaa05c4c27629d46ddda4f
data/bin/finnish-holidays CHANGED
@@ -10,13 +10,13 @@ options = {}
10
10
 
11
11
  optparse = OptionParser.new do |opts|
12
12
  options[:count] = 3
13
- opts.on('-cCOUNT', '--count=COUNT', 'Number of holidays to show') do |count|
13
+ opts.on('-cCOUNT', '--count=COUNT', 'Number of holidays to list') do |count|
14
14
  options[:count] = count.to_i
15
15
  end
16
16
 
17
- options[:all] = false
17
+ options[:include_weekends] = false
18
18
  opts.on('-a', '--all', 'Include holidays falling on a weekend') do
19
- options[:all] = true
19
+ options[:include_weekends] = true
20
20
  end
21
21
 
22
22
  opts.on('-h', '--help', 'Show this screen') do
@@ -28,11 +28,31 @@ optparse = OptionParser.new do |opts|
28
28
  puts FinnishHolidays::VERSION
29
29
  exit
30
30
  end
31
+
32
+ options[:year] = nil
33
+ opts.on('-yYEAR', '--year=YEAR', 'List holidays by year') do |year|
34
+ options[:year] = year.to_i
35
+ end
36
+
37
+ options[:month] = nil
38
+ opts.on('-mMONTH', '--month=MONTH', 'List holidays by month') do |month|
39
+ options[:month] = month.to_i
40
+ end
31
41
  end
32
42
 
33
43
  optparse.parse!
34
44
 
35
- holidays = FinnishHolidays.holidays(options[:count], options[:all])
45
+ if options[:month].is_a? Integer and !options[:year].is_a? Integer
46
+ puts 'You must also specify a year with --year=YEAR'
47
+ exit
48
+ elsif options[:year].is_a? Integer and options[:month].is_a? Integer
49
+ holidays = FinnishHolidays.month(options[:month], options[:year], options[:include_weekends])
50
+ elsif options[:year].is_a? Integer
51
+ holidays = FinnishHolidays.year(options[:year], options[:include_weekends])
52
+ else
53
+ holidays = FinnishHolidays.next(options[:count], options[:include_weekends])
54
+ end
55
+
36
56
  holidays.each do |holiday|
37
57
  t = DateUtils.create_date(holiday['year'], holiday['month'], holiday['day'])
38
58
  date = t.strftime('%a, %b %e, %Y')
@@ -6,14 +6,15 @@ require_relative '../utils/date-utils'
6
6
  class Calendar
7
7
  MAX_HOLIDAYS = 100
8
8
 
9
- def initialize()
10
- @y = Time.now.year
11
- @m = Time.now.month
12
- @d = Time.now.day
9
+ def initialize(y = nil, m = nil, d = nil)
10
+ @y = y == nil ? Time.now.year : y
11
+ @m = m == nil ? Time.now.month : m
12
+ @d = d == nil ? Time.now.day : d
13
+
13
14
  @year = Year.new(@y)
14
15
  end
15
16
 
16
- def holidays(count = 3, all = false)
17
+ def next(count = 3, include_weekends = false)
17
18
  if count > MAX_HOLIDAYS
18
19
  raise "Cannot request more than #{MAX_HOLIDAYS} holidays at once."
19
20
  end
@@ -23,7 +24,7 @@ class Calendar
23
24
  while holidays.length < count
24
25
  month_index = @m.to_s
25
26
 
26
- if !all
27
+ if !include_weekends
27
28
  @year.discard_weekends()
28
29
  end
29
30
 
@@ -43,6 +44,38 @@ class Calendar
43
44
  holidays
44
45
  end
45
46
 
47
+ def year(year, weekends = false)
48
+ if !weekends
49
+ @year.discard_weekends()
50
+ end
51
+
52
+ holidays = []
53
+
54
+ @year.holidays.each do |month, array|
55
+ array.each do |holiday|
56
+ holidays.push(holiday)
57
+ end
58
+ end
59
+
60
+ holidays
61
+ end
62
+
63
+ def month(month, year, weekends = false)
64
+ if !weekends
65
+ @year.discard_weekends()
66
+ end
67
+
68
+ holidays = []
69
+
70
+ if @year.holidays[month.to_s].is_a? Array
71
+ @year.holidays[month.to_s].each do |holiday|
72
+ holidays.push(holiday)
73
+ end
74
+ end
75
+
76
+ holidays
77
+ end
78
+
46
79
  private
47
80
 
48
81
  def next_month
data/lib/classes/year.rb CHANGED
@@ -77,8 +77,10 @@ private
77
77
  month = month.to_i
78
78
  day = day.to_i
79
79
 
80
- if !@holidays[month].is_a? Array
81
- @holidays[month] = []
80
+ month_index = month.to_s
81
+
82
+ if !@holidays[month_index].is_a? Array
83
+ @holidays[month_index] = []
82
84
  end
83
85
 
84
86
  holiday = {
@@ -88,7 +90,7 @@ private
88
90
  'description' => description
89
91
  }
90
92
 
91
- @holidays[month].push(holiday)
93
+ @holidays[month_index].push(holiday)
92
94
  end
93
95
 
94
96
  def cache
@@ -1,7 +1,18 @@
1
1
  require_relative 'classes/calendar'
2
2
 
3
3
  module FinnishHolidays
4
- def self.holidays(count = 3, all = false)
5
- Calendar.new.holidays(count, all)
4
+ # Lists the next holidays relative to today's date
5
+ def self.next(count = 3, include_weekends = false)
6
+ Calendar.new.next(count, include_weekends)
7
+ end
8
+
9
+ # Lists holidays for the given year
10
+ def self.year(year, include_weekends = false)
11
+ Calendar.new(year, 1, 1).year(year, include_weekends)
12
+ end
13
+
14
+ # Lists holidays for the given month (and year)
15
+ def self.month(month, year, include_weekends = false)
16
+ Calendar.new(year, month, 1).month(month, year, include_weekends)
6
17
  end
7
18
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FinnishHolidays
2
- VERSION = '0.1.6'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finnish-holidays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Nishio
@@ -14,56 +14,56 @@ dependencies:
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  description: A CLI and library for displaying Finnish national holidays.
@@ -74,10 +74,10 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - ".editorconfig"
78
- - ".gitignore"
79
- - ".rspec"
80
- - ".travis.yml"
77
+ - .editorconfig
78
+ - .gitignore
79
+ - .rspec
80
+ - .travis.yml
81
81
  - Gemfile
82
82
  - Gemfile.lock
83
83
  - LICENSE.txt
@@ -102,17 +102,17 @@ require_paths:
102
102
  - lib
103
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ">="
105
+ - - '>='
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ">="
110
+ - - '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.2.2
115
+ rubygems_version: 2.0.14
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: A tool for displaying Finnish national holidays.