Class: Post_id_rss
- Inherits:
-
Object
- Object
- Post_id_rss
- Defined in:
- lib/abelard/postxml.rb
Instance Attribute Summary collapse
-
#idurl ⇒ Object
readonly
Returns the value of attribute idurl.
Instance Method Summary collapse
- #as_comment(commentnumber) ⇒ Object
- #improvise ⇒ Object
-
#initialize(postxml) ⇒ Post_id_rss
constructor
A new instance of Post_id_rss.
- #post_match ⇒ Object
- #sanitize ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(postxml) ⇒ Post_id_rss
Returns a new instance of Post_id_rss.
26 27 28 29 30 |
# File 'lib/abelard/postxml.rb', line 26 def initialize(postxml) #XmlUtil::child_content(postxml, "post_id") || @idurl = XmlUtil::child_content(postxml, "guid") @raw = postxml.to_s end |
Instance Attribute Details
#idurl ⇒ Object (readonly)
Returns the value of attribute idurl.
25 26 27 |
# File 'lib/abelard/postxml.rb', line 25 def idurl @idurl end |
Instance Method Details
#as_comment(commentnumber) ⇒ Object
59 60 61 |
# File 'lib/abelard/postxml.rb', line 59 def as_comment(commentnumber) "comment-#{post_match}-#{commentnumber}.xml" end |
#improvise ⇒ Object
76 77 78 |
# File 'lib/abelard/postxml.rb', line 76 def improvise "post-%016x.xml" % @raw.hash end |
#post_match ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/abelard/postxml.rb', line 50 def post_match posturl = /\?p(age_id)?=(\d+)(\.xml)?$/.match(idurl) if posturl posturl[2] else sanitize end end |
#sanitize ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/abelard/postxml.rb', line 63 def sanitize uri = URI(idurl) $stderr.puts("Could not parse url #{idurl}") unless ( uri ) if ( uri.scheme == "tag" ) return idurl.split('-').last end build = uri.path.sub(/^\//,'').sub(/\.xml$/,'').gsub('/','-') build.concat('-' + uri.query.gsub(/[?&]/,'-')) if uri.query build.concat('-' + uri.fragment) if uri.fragment build end |
#to_s ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/abelard/postxml.rb', line 32 def to_s if !idurl improvise else postnumber = post_match commenturl = /\?p(age_id)?=(\d+)(\.xml)?#comment-(.*)$/.match(idurl) || /^(.*)\/(\d{4}\/.*)\/#(comment)-(.*)$/.match(idurl) if commenturl postnumber = commenturl[2].sub(/^\//,'').sub(/\.xml$/,'').gsub('/','-') commentnumber = commenturl[4] "comment-#{postnumber}-#{commentnumber}.xml" else "post-#{postnumber}.xml" end end end |