Class: NationalDayList

Inherits:
Object
  • Object
show all
Defined in:
lib/nationaldaylist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(use_cache = true) ⇒ NationalDayList

Returns a new instance of NationalDayList.



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

def initialize(use_cache=true)
	@use_cache = use_cache
	@cache = {}
end

Instance Attribute Details

#use_cacheObject

Returns the value of attribute use_cache.



5
6
7
# File 'lib/nationaldaylist.rb', line 5

def use_cache
  @use_cache
end

Instance Method Details

#cached?(input) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/nationaldaylist.rb', line 23

def cached?(input)
	@cache[get_month_id(input)]!=nil&&use_cache
end

#clear_cacheObject



27
28
29
# File 'lib/nationaldaylist.rb', line 27

def clear_cache
	@cache = {}
end

#get_month(input) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/nationaldaylist.rb', line 15

def get_month(input)
	id = get_month_id(input)
	month = @cache[id] if use_cache
	month = DayOfMonth.array_from_hash_array(Scraper.scrape_month("#{URL_BASE}#{id}/")) if @cache[id]==nil || !use_cache
	@cache[id] = month if use_cache
	month
end