Class: MotiroReporter

Inherits:
Object
  • Object
show all
Defined in:
app/core/reporter.rb

Overview

A reporter is someone capable of going out for news

For a Motiro reporter, “going out” may include, but is not limited to, accessing the local file system, executing external processes and consulting the web

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add(code) ⇒ Object

Adds a button to this reporter’s toolbar. Accepts a text parameter that will be fed into the ERB templates when generating web pages.

It is a better idea to use one of the buttons available on the buttons hash than to hard-code the button code.



58
59
60
# File 'app/core/reporter.rb', line 58

def self.add(code)
  write_inheritable_array 'buttons', [code]
end

.buttonObject

A hash of buttons available for reporters

Usage : class MyReporter < MotiroReporter

  add_button buttons[:older]
end


67
68
69
# File 'app/core/reporter.rb', line 67

def self.button
  @@buttons ||= { :older => OLDER_BUTTON }
end

.caching(switch) ⇒ Object

Turns caching on and off for the reporter

Usage : class MyReporter < MotiroReporter

  caching :off
end


76
77
78
# File 'app/core/reporter.rb', line 76

def self.caching(switch)
  define_method :cache? do; :off != switch; end
end

.reporter_nameObject



33
34
35
36
# File 'app/core/reporter.rb', line 33

def self.reporter_name
  class_name = self.name
  return class_name[0, class_name.size - 8].underscore
end

.title(title) ⇒ Object

Replaces the default title with a custom one. Example usage:

class MyReporter < MotiroReporter
    title "This is my reporter's custom title"
end

MyReporter.new.channel_title => "This is my reporter's custom title"

If not called, a default title will be generated based on the class name



47
48
49
50
51
# File 'app/core/reporter.rb', line 47

def self.title(title)
  define_method :channel_title do
    title.t
  end
end

Instance Method Details

#buttonsObject



88
89
90
# File 'app/core/reporter.rb', line 88

def buttons
  self.class.read_inheritable_attribute 'buttons' || []
end

#cache?Boolean

Returns:

  • (Boolean)


96
# File 'app/core/reporter.rb', line 96

def cache?; true; end

#channel_titleObject



84
85
86
# File 'app/core/reporter.rb', line 84

def channel_title
  return 'Latest news from %s' / name.humanize
end

#latest_headlineObject



98
99
100
# File 'app/core/reporter.rb', line 98

def latest_headline
  return latest_headlines.first
end

#nameObject



80
81
82
# File 'app/core/reporter.rb', line 80

def name
  return self.class.reporter_name
end

#params_for(rid) ⇒ Object



92
93
94
# File 'app/core/reporter.rb', line 92

def params_for(rid)
  {:controller => 'report', :action => 'show', :reporter => name, :id => rid}
end