Module: TD2Planet
- Defined in:
- lib/td2planet/version.rb,
lib/td2planet/runner.rb,
lib/td2planet/writer.rb,
lib/td2planet/fetcher.rb,
lib/td2planet/formatter.rb,
lib/td2planet/sample_formatter.rb,
lib/td2planet/default_formatter.rb
Overview
vim: set filetype=ruby ts=2 sw=2 sts=2:
copyright © 2006, 2007, 2009, 2013 Kazuhiro NISHIYAMA
Defined Under Namespace
Classes: DefaultFormatter, Fetcher, Formatter, SampleFormatter, Writer
Constant Summary collapse
- TD2PLANET_VERSION =
"0.3.0"
- TD2PLANET_RELEASE_DATE =
"2013-09-12"
Class Method Summary collapse
-
.generator ⇒ Object
return string for meta generator (see templates/layout.rhtml).
- .get_formatter_class(formatter_name) ⇒ Object
- .main(argv = ARGV) ⇒ Object
-
.ruby_version ⇒ Object
return ruby version string (simulate output of ruby -v).
- .run(config) ⇒ Object
-
.td2planet_version ⇒ Object
return TD2Planet version string.
Class Method Details
.generator ⇒ Object
return string for meta generator (see templates/layout.rhtml)
27 28 29 |
# File 'lib/td2planet/version.rb', line 27 def self.generator "#{td2planet_version} / Powered by #{ruby_version}" end |
.get_formatter_class(formatter_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/td2planet/runner.rb', line 32 def get_formatter_class(formatter_name) formatter_class_name = formatter_name.gsub(/(^|_)(.)/) { $2.upcase } begin require formatter_name rescue LoadError begin require "td2planet/#{formatter_name}" rescue LoadError raise LoadError, "no such formatter: #{formatter_name}" end end formatter = const_get(formatter_class_name) end |
.main(argv = ARGV) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/td2planet/runner.rb', line 15 def main(argv=ARGV) opts = OptionParser.new usage = proc { puts opts; exit(1) } opts. << " config.yaml" @dry_run = false opts.on('-n', '--dry-run', 'do not fetch, generate files only') { @dry_run = true } opts.on('-h', '--help', 'show this message') { usage.call } opts.parse!(argv) if argv.empty? usage.call end argv.each do |filename| config = YAML.load(File.read(filename)) run(config) end end |
.ruby_version ⇒ Object
return ruby version string (simulate output of ruby -v)
11 12 13 14 15 16 17 18 19 |
# File 'lib/td2planet/version.rb', line 11 def self.ruby_version if defined?(RUBY_DESCRIPTION) RUBY_DESCRIPTION elsif defined?(RUBY_PATCHLEVEL) "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]" else "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" end end |
.run(config) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/td2planet/runner.rb', line 46 def run(config) formatter_name = config['formatter'] || 'default_formatter' formatter = get_formatter_class(formatter_name).new(config) writer = Writer.new(config, formatter) fetcher = Fetcher.new(config['cache_dir'], @dry_run) rss_list = fetcher.fetch_all_rss(config['uri']) writer.output_html(rss_list) writer.output_opml(rss_list) writer.output_rss(rss_list) end |
.td2planet_version ⇒ Object
return TD2Planet version string
22 23 24 |
# File 'lib/td2planet/version.rb', line 22 def self.td2planet_version "TD2Planet #{TD2PLANET_VERSION} (#{TD2PLANET_RELEASE_DATE})" end |