Class: Bwkfanboy::Parse
- Inherits:
-
Object
- Object
- Bwkfanboy::Parse
- Defined in:
- lib/bwkfanboy/parser.rb
Overview
:include: ../../doc/plugin.rdoc
Direct Known Subclasses
Constant Summary collapse
- ENTRIES_MAX =
128
Instance Attribute Summary collapse
-
#opt ⇒ Object
readonly
Returns the value of attribute opt.
Instance Method Summary collapse
-
#check ⇒ Object
After loading a plugin, one can do basic validation of the plugin’s class with the help of this method.
-
#dump ⇒ Object
Prints entries in ‘key: value’ formatted strings.
-
#dump_info ⇒ Object
Prints plugin’s meta information.
-
#initialize(opt = []) ⇒ Parse
constructor
A new instance of Parse.
-
#parse(stream) ⇒ Object
Invokes #myparse & checks if it has grabbed something.
- #to_json ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(opt = []) ⇒ Parse
Returns a new instance of Parse.
15 16 17 18 |
# File 'lib/bwkfanboy/parser.rb', line 15 def initialize(opt = []) @entries = [] @opt = opt end |
Instance Attribute Details
#opt ⇒ Object (readonly)
Returns the value of attribute opt.
13 14 15 |
# File 'lib/bwkfanboy/parser.rb', line 13 def opt @opt end |
Instance Method Details
#check ⇒ Object
After loading a plugin, one can do basic validation of the plugin’s class with the help of this method.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bwkfanboy/parser.rb', line 75 def check m = () begin [:URI, :ENC, :VERSION, :COPYRIGHT, :TITLE, :CONTENT_TYPE].each {|i| fail "#{m}::#{i} not defined or empty" if (! m.const_defined?(i) || m.const_get(i) =~ /^\s*$/) } if m::URI =~ /#\{.+?\}/ && @opt.size == 0 fail 'additional options required' end rescue Utils.errx(1, "incomplete plugin's instance: #{$!}") end end |
#dump ⇒ Object
Prints entries in ‘key: value’ formatted strings. Intended for debugging.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bwkfanboy/parser.rb', line 39 def dump() @entries.each {|i| puts "title : " + i[:title] puts "link : " + i[:link] puts "updated : " + i[:updated] puts "author : " + i[:author] puts "content : " + i[:content] puts "" } end |
#dump_info ⇒ Object
Prints plugin’s meta information.
91 92 93 94 95 96 97 |
# File 'lib/bwkfanboy/parser.rb', line 91 def dump_info() m = () puts "Version : #{m::VERSION}" puts "Copyright : #{m::COPYRIGHT}" puts "Title : #{m::TITLE}" puts "URI : #{uri}" end |
#parse(stream) ⇒ Object
Invokes #myparse & checks if it has grabbed something.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bwkfanboy/parser.rb', line 21 def parse(stream) @entries = [] begin myparse(stream) rescue @entries = [] Utils.errx(1, "parsing failed: #{$!}\n\nBacktrace:\n\n#{$!.backtrace.join("\n")}") end Utils.errx(1, "plugin return no output") if @entries.length == 0 end |
#to_json ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bwkfanboy/parser.rb', line 50 def to_json() # guess the time of the most recent entry u = DateTime.parse() # January 1, 4713 BCE @entries.each {|i| t = DateTime.parse(i[:updated]) u = t if t > u } m = () j = { channel: { updated: u, id: m::URI, author: Meta::NAME, # just a placeholder title: m::TITLE, link: m::URI, x_entries_content_type: m::CONTENT_TYPE }, x_entries: @entries } Utils::cfg[:verbose] >= 1 ? JSON.pretty_generate(j) : JSON.generate(j) end |
#uri ⇒ Object
32 33 34 35 |
# File 'lib/bwkfanboy/parser.rb', line 32 def uri() m = () eval("\"#{m::URI}\"") end |