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

Class Method Summary collapse

Class Attribute Details

.countryObject

Returns the value of attribute country.



10
11
12
# File 'lib/holiday.rb', line 10

def country
  @country
end

.yaml_fileObject

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

.allObject

Returns all holidays



29
30
31
# File 'lib/holiday.rb', line 29

def all
  Builder.build.keys
end

.country_holidaysObject



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

.holidaysObject



46
47
48
# File 'lib/holiday.rb', line 46

def holidays
  yaml[country].keys
end

.include?(holiday) ⇒ Boolean

Returns:

  • (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

.yamlObject



42
43
44
# File 'lib/holiday.rb', line 42

def yaml
  @yaml ||= YAML.load_file(yaml_file)["holiday"]
end