Class: Rtlog::MonthPage

Inherits:
Page
  • Object
show all
Defined in:
lib/rtlog/pages.rb

Instance Attribute Summary collapse

Attributes inherited from Page

#config, #log, #logger

Instance Method Summary collapse

Methods inherited from Page

#config_dir, #generate, #index_url, #month_pages, #parse, #size, #template_file_name, #template_path

Constructor Details

#initialize(config, log, month_entry) ⇒ MonthPage

Returns a new instance of MonthPage.



144
145
146
147
148
149
# File 'lib/rtlog/pages.rb', line 144

def initialize config, log, month_entry
  @config       = config
  @log          = log
  @month_entry  = month_entry
  @current_page = 1
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



142
143
144
# File 'lib/rtlog/pages.rb', line 142

def current_page
  @current_page
end

#month_entryObject (readonly)

Returns the value of attribute month_entry.



141
142
143
# File 'lib/rtlog/pages.rb', line 141

def month_entry
  @month_entry
end

Instance Method Details

#current_day_pagesObject



159
160
161
162
163
164
165
# File 'lib/rtlog/pages.rb', line 159

def current_day_pages
  current_day_pages = []
  month_entry.day_entries[(current_page - 1) * per_page, per_page].each do |d|
    current_day_pages << DayPage.new( config, log, d )
  end
  current_day_pages
end

#dateObject



155
156
157
# File 'lib/rtlog/pages.rb', line 155

def date
  @month_entry.date
end

#file_pathObject



216
217
218
219
# File 'lib/rtlog/pages.rb', line 216

def file_path
  page = current_page == 1 ? '' : "_#{current_page}"
  File.expand_path( File.join(config['target_dir'], path, "index#{page}.html") )
end

#nextObject



191
192
193
194
195
196
# File 'lib/rtlog/pages.rb', line 191

def next
  return false if current_page == total_pages
  next_page = self.clone
  next_page.current_page += 1
  next_page
end

#next_month_pageObject



198
199
200
201
202
203
204
205
# File 'lib/rtlog/pages.rb', line 198

def next_month_page
  unless defined?(@next_month_page)
    month = log.next_month_entry(self.month_entry)
    return nil unless month
    @next_month_page = MonthPage.new(config, log, month)
  end
  @next_month_page
end

#per_pageObject



167
168
169
# File 'lib/rtlog/pages.rb', line 167

def per_page
  size
end

#previousObject



184
185
186
187
188
189
# File 'lib/rtlog/pages.rb', line 184

def previous
  return false if current_page == 1
  previous_page = self.clone
  previous_page.current_page -= 1
  previous_page
end

#previous_month_pageObject



207
208
209
210
211
212
213
214
# File 'lib/rtlog/pages.rb', line 207

def previous_month_page
  unless defined?(@previous_month_page)
    month = log.previous_month_entry(self.month_entry)
    return nil unless month
    @previous_month_page = MonthPage.new(config, log, month)
  end
  @previous_month_page
end

#titleObject



151
152
153
# File 'lib/rtlog/pages.rb', line 151

def title
  date.strftime('%Y-%m')
end

#total_entriesObject



171
172
173
174
# File 'lib/rtlog/pages.rb', line 171

def total_entries
  @total_entries ||= month_entry.day_entries.size
  @total_entries
end

#total_pagesObject



180
181
182
# File 'lib/rtlog/pages.rb', line 180

def total_pages
  (Float.induced_from(total_entries)/Float.induced_from(per_page)).ceil
end

#total_tweetsObject



176
177
178
# File 'lib/rtlog/pages.rb', line 176

def total_tweets
  month_entry.size
end

#url(page = current_page) ⇒ Object



221
222
223
224
# File 'lib/rtlog/pages.rb', line 221

def url(page=current_page)
  page = page == 1 ? '' : "index_#{page}"
  config['url_prefix'] + '/' + path + '/' + page
end