Class: Hackernews::HomeState
- Inherits:
-
ApplicationState
- Object
- Charming::ApplicationState
- ApplicationState
- Hackernews::HomeState
- Defined in:
- app/state/home_state.rb
Instance Attribute Summary collapse
-
#articles_by_story_id ⇒ Object
Returns the value of attribute articles_by_story_id.
-
#extracting_story_id ⇒ Object
Returns the value of attribute extracting_story_id.
-
#failed_pages ⇒ Object
Returns the value of attribute failed_pages.
-
#loading_key ⇒ Object
Returns the value of attribute loading_key.
-
#stories_by_page ⇒ Object
Returns the value of attribute stories_by_page.
-
#story_ids_by_feed ⇒ Object
Returns the value of attribute story_ids_by_feed.
Instance Method Summary collapse
- #article ⇒ Object
- #cached_page? ⇒ Boolean
- #current_stories ⇒ Object
- #current_story_ids ⇒ Object
- #failed_page? ⇒ Boolean
-
#initialize(**attributes) ⇒ HomeState
constructor
A new instance of HomeState.
- #page_key(feed_name = feed, page_number = page) ⇒ Object
- #reading? ⇒ Boolean
- #reset_list_position ⇒ Object
- #selected_story ⇒ Object
- #selected_story=(story) ⇒ Object
- #working? ⇒ Boolean
Constructor Details
#initialize(**attributes) ⇒ HomeState
Returns a new instance of HomeState.
19 20 21 22 23 24 25 |
# File 'app/state/home_state.rb', line 19 def initialize(**attributes) super @story_ids_by_feed = {} @stories_by_page = {} @articles_by_story_id = {} @failed_pages = {} end |
Instance Attribute Details
#articles_by_story_id ⇒ Object
Returns the value of attribute articles_by_story_id.
16 17 18 |
# File 'app/state/home_state.rb', line 16 def articles_by_story_id @articles_by_story_id end |
#extracting_story_id ⇒ Object
Returns the value of attribute extracting_story_id.
16 17 18 |
# File 'app/state/home_state.rb', line 16 def extracting_story_id @extracting_story_id end |
#failed_pages ⇒ Object
Returns the value of attribute failed_pages.
16 17 18 |
# File 'app/state/home_state.rb', line 16 def failed_pages @failed_pages end |
#loading_key ⇒ Object
Returns the value of attribute loading_key.
16 17 18 |
# File 'app/state/home_state.rb', line 16 def loading_key @loading_key end |
#stories_by_page ⇒ Object
Returns the value of attribute stories_by_page.
16 17 18 |
# File 'app/state/home_state.rb', line 16 def stories_by_page @stories_by_page end |
#story_ids_by_feed ⇒ Object
Returns the value of attribute story_ids_by_feed.
16 17 18 |
# File 'app/state/home_state.rb', line 16 def story_ids_by_feed @story_ids_by_feed end |
Instance Method Details
#article ⇒ Object
55 56 57 |
# File 'app/state/home_state.rb', line 55 def article articles_by_story_id[reading_story_id] end |
#cached_page? ⇒ Boolean
39 40 41 |
# File 'app/state/home_state.rb', line 39 def cached_page? stories_by_page.key?(page_key) end |
#current_stories ⇒ Object
31 32 33 |
# File 'app/state/home_state.rb', line 31 def current_stories stories_by_page.fetch(page_key, []) end |
#current_story_ids ⇒ Object
35 36 37 |
# File 'app/state/home_state.rb', line 35 def current_story_ids story_ids_by_feed.fetch(feed, []) end |
#failed_page? ⇒ Boolean
43 44 45 |
# File 'app/state/home_state.rb', line 43 def failed_page? failed_pages[page_key] end |
#page_key(feed_name = feed, page_number = page) ⇒ Object
27 28 29 |
# File 'app/state/home_state.rb', line 27 def page_key(feed_name = feed, page_number = page) "#{feed_name}:#{page_number.to_i}" end |
#reading? ⇒ Boolean
59 60 61 |
# File 'app/state/home_state.rb', line 59 def reading? reading_story_id.to_i.positive? end |
#reset_list_position ⇒ Object
67 68 69 70 71 |
# File 'app/state/home_state.rb', line 67 def reset_list_position self.selected_index = 0 self.article_scroll = 0 self.reading_story_id = nil end |
#selected_story ⇒ Object
47 48 49 |
# File 'app/state/home_state.rb', line 47 def selected_story current_stories[selected_index] end |
#selected_story=(story) ⇒ Object
51 52 53 |
# File 'app/state/home_state.rb', line 51 def selected_story=(story) self.selected_index = current_stories.index(story) || 0 end |
#working? ⇒ Boolean
63 64 65 |
# File 'app/state/home_state.rb', line 63 def working? (loading && !cached_page?) || extracting_story_id.to_i.positive? end |