finnish-holidays 0.2.1 → 0.2.2

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: 0cda9ea0464c10d0147a093960444d55883c2548
4
- data.tar.gz: 5fb9c50314e9df7ce28400b75fd699d23d011d52
3
+ metadata.gz: 2a96fdda7e141d2aeef96e7411d75713a4859bb2
4
+ data.tar.gz: 8107710192f342dde63a4c4059f95c28b7defd97
5
5
  SHA512:
6
- metadata.gz: 20ff03c4dfa1cc7fb0aac9ea0250c22209a1e48a6a382b64e6cfb9fdcd5c9a1fc3cd509f0f4dcf9da8d17e2126207958b3044be2e8082b321c20fd960e46b4bb
7
- data.tar.gz: 6750e3af9d2ceaff7998fed6a5d17d3e23dc974ad9aabcc9b86dc46d40e9569933fb200efe325b1b53cbf15f5bbefd4740efb658ca6cbe8797187e91e3508f44
6
+ metadata.gz: 00aa8f9d3798e07f3c297ce2c83ff5cb326dc6e27d3b1bd4ee92ed1d3dc37980907b96ddc6233116faea0b0234436b564eaa412acba700b862720465aaa416df
7
+ data.tar.gz: 10e5409dd54d31472a15e3a306d6bc7a174e15ff26cb634e87cdfb0b893bcad5baea6b0823c779b1029377294714d011be7f15a1986aeee2ffb4c6a8f37d5bc6
data/README.md CHANGED
@@ -24,3 +24,7 @@ FinnishHolidays.next()
24
24
  FinnishHolidays.year(2016)
25
25
  FinnishHolidays.month(1, 2017)
26
26
  ```
27
+
28
+ ## Run Tests
29
+
30
+ $ rspec
data/bin/finnish-holidays CHANGED
@@ -42,10 +42,10 @@ end
42
42
 
43
43
  optparse.parse!
44
44
 
45
- if options[:month].is_a? Integer and !options[:year].is_a? Integer
45
+ if (options[:month].is_a? Integer) && (!options[:year].is_a? Integer)
46
46
  puts 'You must also specify a year with --year=YEAR'
47
47
  exit
48
- elsif options[:year].is_a? Integer and options[:month].is_a? Integer
48
+ elsif (options[:year].is_a? Integer) && (options[:month].is_a? Integer)
49
49
  holidays = FinnishHolidays.month(options[:month], options[:year], options[:include_weekends])
50
50
  elsif options[:year].is_a? Integer
51
51
  holidays = FinnishHolidays.year(options[:year], options[:include_weekends])
@@ -28,9 +28,9 @@ class Calendar
28
28
  @year.discard_weekends()
29
29
  end
30
30
 
31
- if defined? @year.holidays[month_index] and @year.holidays[month_index].is_a? Array
31
+ if (defined? @year.holidays[month_index]) && (@year.holidays[month_index].is_a? Array)
32
32
  @year.holidays[month_index].each do |holiday|
33
- if holidays.length < count and holiday['day'].to_i >= @d
33
+ if (holidays.length < count) && (holiday['day'].to_i >= @d)
34
34
  holidays.push(holiday)
35
35
  end
36
36
  end
data/lib/classes/year.rb CHANGED
@@ -6,7 +6,7 @@ require_relative '../utils/date-utils'
6
6
 
7
7
  class Year
8
8
  def initialize(year)
9
- if year.is_a? Integer and year > 0
9
+ if (year.is_a? Integer) && (year > 0)
10
10
  @year = year.to_i
11
11
  @holidays = {}
12
12
  load_data()
@@ -46,6 +46,7 @@ private
46
46
  load_from_file()
47
47
  else
48
48
  load_from_web()
49
+ load_additional_holidays()
49
50
  cache()
50
51
  end
51
52
  end
@@ -72,7 +73,12 @@ private
72
73
  end
73
74
  end
74
75
 
75
- def add_holiday(year, month, day, description)
76
+ def load_additional_holidays
77
+ add_holiday(@year, 12, 24, 'Jouluaatto (unofficial)', true)
78
+ add_holiday(@year, 6, DateUtils.get_midsummer_eve(@year), 'Juhannusaatto (unofficial)', true)
79
+ end
80
+
81
+ def add_holiday(year, month, day, description, find_position = false)
76
82
  year = year.to_i
77
83
  month = month.to_i
78
84
  day = day.to_i
@@ -90,7 +96,20 @@ private
90
96
  'description' => description
91
97
  }
92
98
 
93
- @holidays[month_index].push(holiday)
99
+ if find_position && (@holidays[month_index].length > 0)
100
+ found = false
101
+
102
+ @holidays[month_index].each_with_index do |h, index|
103
+ if !found
104
+ if day.to_i < h['day'].to_i
105
+ @holidays[month_index].insert(index, holiday)
106
+ found = true
107
+ end
108
+ end
109
+ end
110
+ else
111
+ @holidays[month_index].push(holiday)
112
+ end
94
113
  end
95
114
 
96
115
  def cache
@@ -1,4 +1,8 @@
1
1
  class DateUtils
2
+ FRIDAY = 5
3
+ SATURDAY = 6
4
+ SUNDAY = 7
5
+
2
6
  def self.create_date(year, month, day)
3
7
  day = self.zerofy(day)
4
8
  month = self.zerofy(month)
@@ -20,7 +24,16 @@ class DateUtils
20
24
  def self.is_weekend(year, month, day)
21
25
  t = self.create_date(year, month, day)
22
26
  day_of_week = t.strftime('%u').to_i
23
- day_of_week == 6 or day_of_week == 7
27
+ [SATURDAY, SUNDAY].include? day_of_week
28
+ end
29
+
30
+ def self.get_midsummer_eve(year)
31
+ [19, 20, 21, 22, 23, 24, 25].each do |day|
32
+ day_of_week = self.create_date(year, 6, day).strftime('%u').to_i
33
+ if day_of_week == FRIDAY
34
+ return day
35
+ end
36
+ end
24
37
  end
25
38
 
26
39
  def self.zerofy(num)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FinnishHolidays
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finnish-holidays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Nishio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-26 00:00:00.000000000 Z
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri