Class: NationalDayList
- Inherits:
-
Object
- Object
- NationalDayList
- Defined in:
- lib/nationaldaylist.rb
Instance Attribute Summary collapse
-
#use_cache ⇒ Object
Returns the value of attribute use_cache.
Instance Method Summary collapse
- #cached?(input) ⇒ Boolean
- #clear_cache ⇒ Object
- #get_month(input) ⇒ Object
-
#initialize(use_cache = true) ⇒ NationalDayList
constructor
A new instance of NationalDayList.
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_cache ⇒ Object
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
23 24 25 |
# File 'lib/nationaldaylist.rb', line 23 def cached?(input) @cache[get_month_id(input)]!=nil&&use_cache end |
#clear_cache ⇒ Object
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 |