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
# 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
  @cache    = PageFetcher.new(@comments_info.page) if @comments_info
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



34
35
36
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 34

def self.all(pages = 1)
  return EntryService.new.get_entries(pages)
end

.ask(title, text) ⇒ Object



78
79
80
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 78

def self.ask(title, text)
  return EntryService.new.ask(title, text)
end

.find(id) ⇒ Object



50
51
52
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 50

def self.find(id)
  return EntryService.new.find_by_id(id)
end

.jobs(pages = 1) ⇒ Object



46
47
48
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 46

def self.jobs(pages = 1)
  return EntryService.new.get_jobs(pages)
end

.newest(pages = 1) ⇒ Object



38
39
40
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 38

def self.newest(pages = 1)
  return EntryService.new.get_new_entries(pages)
end

.questions(pages = 1) ⇒ Object



42
43
44
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 42

def self.questions(pages = 1)
  return EntryService.new.get_questions(pages)
end

.submit(title, url) ⇒ Object



74
75
76
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 74

def self.submit(title, url)
  return EntryService.new.submit(title, url)
end

Instance Method Details

#commentsObject



27
28
29
30
31
32
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 27

def comments
  unless @comments
    @comments = CommentService.new.get_comments(@cache.page)
  end
  return @comments
end

#comments_countObject



66
67
68
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 66

def comments_count
  return @comments_info.count unless @comments_info.nil?
end

#comments_urlObject



62
63
64
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 62

def comments_url
  return @comments_info ? ConfigurationService.base_url + @comments_info.url : nil
end

#idObject



58
59
60
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 58

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

#textObject



20
21
22
23
24
25
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 20

def text
  unless @text
    @text = TextService.new.get_text(@cache.page)
  end
  return @text
end

#timeObject



54
55
56
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 54

def time
  return @time.time
end

#upvoteObject



82
83
84
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 82

def upvote
  return VotingService.new.vote(@voting.upvote)
end

#write_comment(text) ⇒ Object



70
71
72
# File 'lib/ruby-hackernews/domain/entry/entry.rb', line 70

def write_comment(text)
  return CommentService.new.write_comment(@comments_info.page, text)
end