class NationalDayList
Attributes
use_cache[RW]
Public Class Methods
new(use_cache=true)
click to toggle source
# File lib/nationaldaylist.rb, line 10 def initialize(use_cache=true) @use_cache = use_cache @cache = {} end
Public Instance Methods
cached?(input)
click to toggle source
# File lib/nationaldaylist.rb, line 23 def cached?(input) @cache[get_month_id(input)]!=nil&&use_cache end
clear_cache()
click to toggle source
# File lib/nationaldaylist.rb, line 27 def clear_cache @cache = {} end
get_month(input)
click to toggle source
# 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
Private Instance Methods
get_month_id(input)
click to toggle source
# File lib/nationaldaylist.rb, line 32 def get_month_id(input) index = get_month_index(input) return MONTHS[index] unless index < 0 nil end
get_month_index(input)
click to toggle source
# File lib/nationaldaylist.rb, line 38 def get_month_index(input) return input if input.class==Fixnum return input.to_i()-1 unless input.to_i()==0 MONTHS.find_index(input.downcase) end