Class: RubyHackernews::Entry
- Inherits:
-
Object
- Object
- RubyHackernews::Entry
- Defined in:
- lib/ruby-hackernews/domain/entry/entry.rb
Instance Attribute Summary collapse
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#voting ⇒ Object
readonly
Returns the value of attribute voting.
Class Method Summary collapse
- .all(pages = 1) ⇒ Object
- .ask(title, text) ⇒ Object
- .find(id) ⇒ Object
- .jobs(pages = 1) ⇒ Object
- .new_shows(pages = 1) ⇒ Object
- .newest(pages = 1) ⇒ Object
- .newest_with_extra(pages = 1, url = nil) ⇒ Object
- .questions(pages = 1) ⇒ Object
- .shows(pages = 1) ⇒ Object
- .submit(title, url) ⇒ Object
Instance Method Summary collapse
- #comments ⇒ Object
- #comments_count ⇒ Object
- #comments_url ⇒ Object
- #id ⇒ Object
-
#initialize(number, link, voting, user, comments, time) ⇒ Entry
constructor
A new instance of Entry.
- #text ⇒ Object
- #time ⇒ Object
- #upvote ⇒ Object
- #write_comment(text) ⇒ Object
Constructor Details
#initialize(number, link, voting, user, comments, time) ⇒ Entry
Returns a new instance of Entry.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 10 def initialize(number, link, voting, user, comments, time) @number = number @link = link @voting = voting @user = user @time = time @comments_info = comments if @comments_info @cache = PageFetcher.new(@comments_info.page) else @cache = PageFetcher.new(@link.href) end end |
Instance Attribute Details
#link ⇒ Object (readonly)
Returns the value of attribute link.
6 7 8 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 6 def link @link end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
5 6 7 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 5 def number @number end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 8 def user @user end |
#voting ⇒ Object (readonly)
Returns the value of attribute voting.
7 8 9 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 7 def voting @voting end |
Class Method Details
.all(pages = 1) ⇒ Object
38 39 40 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 38 def self.all(pages = 1) return EntryService.new.get_entries(pages) end |
.ask(title, text) ⇒ Object
96 97 98 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 96 def self.ask(title, text) return EntryService.new.ask(title, text) end |
.find(id) ⇒ Object
68 69 70 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 68 def self.find(id) return EntryService.new.find_by_id(id) end |
.jobs(pages = 1) ⇒ Object
56 57 58 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 56 def self.jobs(pages = 1) return EntryService.new.get_jobs(pages) end |
.new_shows(pages = 1) ⇒ Object
64 65 66 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 64 def self.new_shows(pages = 1) return EntryService.new.get_new_shows(pages) end |
.newest(pages = 1) ⇒ Object
42 43 44 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 42 def self.newest(pages = 1) return EntryService.new.get_new_entries(pages) end |
.newest_with_extra(pages = 1, url = nil) ⇒ Object
46 47 48 49 50 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 46 def self.newest_with_extra(pages = 1, url = nil) args = [pages] args << url unless url.nil? return EntryService.new.get_entries_with_extra *args end |
.questions(pages = 1) ⇒ Object
52 53 54 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 52 def self.questions(pages = 1) return EntryService.new.get_questions(pages) end |
.shows(pages = 1) ⇒ Object
60 61 62 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 60 def self.shows(pages = 1) return EntryService.new.get_shows(pages) end |
.submit(title, url) ⇒ Object
92 93 94 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 92 def self.submit(title, url) return EntryService.new.submit(title, url) end |
Instance Method Details
#comments ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 31 def comments unless @comments @comments = CommentService.new.get_comments(@cache.page) end return @comments end |
#comments_count ⇒ Object
84 85 86 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 84 def comments_count return @comments_info.count unless @comments_info.nil? end |
#comments_url ⇒ Object
80 81 82 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 80 def comments_url return @comments_info ? ConfigurationService.base_url + @comments_info.url : nil end |
#id ⇒ Object
76 77 78 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 76 def id return @comments_info ? @comments_info.id : nil end |
#text ⇒ Object
24 25 26 27 28 29 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 24 def text unless @text @text = TextService.new.get_text(@cache.page) end return @text end |
#time ⇒ Object
72 73 74 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 72 def time return @time.time end |
#upvote ⇒ Object
100 101 102 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 100 def upvote return VotingService.new.vote(@voting.upvote) end |
#write_comment(text) ⇒ Object
88 89 90 |
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 88 def write_comment(text) return CommentService.new.write_comment(@comments_info.page, text) end |