Module: Holiday
- Defined in:
- lib/holiday.rb,
lib/holiday/query.rb,
lib/holiday/parser.rb,
lib/holiday/builder.rb,
lib/holiday/version.rb
Defined Under Namespace
Classes: Builder, Parser, Query
Constant Summary collapse
- VERSION =
"0.0.1"
Class Attribute Summary collapse
-
.country ⇒ Object
Returns the value of attribute country.
-
.yaml_file ⇒ Object
Returns the value of attribute yaml_file.
Class Method Summary collapse
-
.all ⇒ Object
Returns all holidays.
- .country_holidays ⇒ Object
- .find(holiday, year = nil) ⇒ Object
- .holidays ⇒ Object
- .include?(holiday) ⇒ Boolean
-
.scan(string) ⇒ Object
holiday = Holiday.all.map { |h| string.scan(h) }.uniq.flatten # return match.
- .yaml ⇒ Object
Class Attribute Details
.country ⇒ Object
Returns the value of attribute country.
10 11 12 |
# File 'lib/holiday.rb', line 10 def country @country end |
.yaml_file ⇒ Object
Returns the value of attribute yaml_file.
10 11 12 |
# File 'lib/holiday.rb', line 10 def yaml_file @yaml_file end |
Class Method Details
.all ⇒ Object
Returns all holidays
29 30 31 |
# File 'lib/holiday.rb', line 29 def all Builder.build.keys end |
.country_holidays ⇒ Object
50 51 52 |
# File 'lib/holiday.rb', line 50 def country_holidays yaml[country] end |
.find(holiday, year = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/holiday.rb', line 12 def find(holiday,year=nil) year = year || Time.now.year holiday = holiday.to_s occurrs = Query.find(holiday) parts = Parser.parse(occurrs) date = if parts.kind_of?(Hash) d = Date.parse("#{parts[:month]} 1 #{year}") weeks = (d.beginning_of_month..d.end_of_month).group_by{|d| d.wday} weeks[parts[:wday]][parts[:occurrence]-1] else Date.parse([parts, year].join(" ")) end end |
.holidays ⇒ Object
46 47 48 |
# File 'lib/holiday.rb', line 46 def holidays yaml[country].keys end |
.include?(holiday) ⇒ Boolean
38 39 40 |
# File 'lib/holiday.rb', line 38 def include?(holiday) all.keys.include?(holiday) end |
.scan(string) ⇒ Object
holiday = Holiday.all.map { |h| string.scan(h) }.uniq.flatten # return match
34 35 36 |
# File 'lib/holiday.rb', line 34 def scan(string) all.map{ |h| string.scan(h) }.uniq.flatten.join end |
.yaml ⇒ Object
42 43 44 |
# File 'lib/holiday.rb', line 42 def yaml @yaml ||= YAML.load_file(yaml_file)["holiday"] end |