Class: RubyHackernews::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-hackernews/domain/entry/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Returns the value of attribute link.



6
7
8
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 6

def link
  @link
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 5

def number
  @number
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 8

def user
  @user
end

#votingObject (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

#commentsObject



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_countObject



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_urlObject



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

#idObject



76
77
78
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 76

def id
  return @comments_info ? @comments_info.id : nil
end

#textObject



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

#timeObject



72
73
74
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 72

def time
  return @time.time
end

#upvoteObject



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