-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.rb
158 lines (103 loc) · 2.57 KB
/
runtime.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require 'pry'
class Blog
attr_accessor :all_posts
def initialize
@all_posts = []
@position = 0
end
def add_post(post)
@all_posts << post
@all_posts = @front_page
@front_page = FrontPage.new
end
end
class FrontPage
def initialize
@position = 0
end
def create_front_page
@all_posts = all_posts.sort_by! {|post, date| post.date}.reverse
end
def input_pg(trigger, method)
trigger = gets.chomp
method = nav_cmds[trigger]
method
end
# def input_pg
# puts "Push N Key for next page"
# info = gets.chomp
# if info == "n"
# turnpage_fwd
# @position = @position + 3
# end
# end
def publish_front_page
page_posts = @all_posts.slice(@position, @position + 3)
page_posts.each do |v|
puts v.title
puts v.date
puts "****************"
puts v.text
puts "----------------"
puts "Displaying #{@position + 1} - #{@position + 3} of #{@all_posts.length} posts"
input_pg
end
end
def turnpage_fwd
nputs " "
posts_to_print = @front_page.slice(@position, @position + 3)
posts_to_print.each do |post|
puts post.date, post.title, post.text
end
end
def turnpage_rwd
puts " "
posts_to_print = @front_page.slice(@position, @position - 3)
posts_to_print.each do |post|
puts post.date, post.title, post.text
end
end
end
class Post
attr_accessor :title
attr_accessor :text
attr_accessor :date
def initialize(title, text, date)
@title = title
@text = text
@date = date
end
def namechange
@title = "*******" + "#{@title}" + "******"
end
end
# class Sponsored < Post
# def initialize(title, text, date)
# @title = title
# @text = text
# @date = date
# end
# def namechange
# @title = "*******" + "#{@title}" + "******"
# end
# end
my_first_post = Post.new("Title 1", "1st body", Time.new)
second_post = Post.new("Title 2", "Body 2", Time.new)
third_post = Post.new("Title 3", "Body 3", Time.new)
fourth_post = Post.new("Title4", "Body4", Time.new)
fifth_post = Post.new("Title5", "Body5", Time.new)
sixth_post = Post.new("Title6", "Body6", Time.new)
sev_post = Post.new("Title7", "Body7", Time.new)
eighth_post = Post.new("Title8", "Body8", Time.new)
fourth_post.namechange
my_blog = Blog.new
my_blog.add_post(my_first_post)
my_blog.add_post(second_post)
my_blog.add_post(third_post)
my_blog.add_post(fourth_post)
my_blog.add_post(fifth_post)
my_blog.add_post(sixth_post)
my_blog.add_post(sev_post)
my_blog.add_post(eighth_post)
my_blog.create_front_page
my_blog.publish_front_page