Class: Flee_to_md::Page
- Inherits:
-
Object
- Object
- Flee_to_md::Page
- Defined in:
- lib/flee_to_md.rb
Instance Attribute Summary collapse
-
#attachment_filename ⇒ Object
Returns the value of attribute attachment_filename.
-
#attachment_url ⇒ Object
Returns the value of attribute attachment_url.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#date ⇒ Object
Returns the value of attribute date.
-
#html ⇒ Object
Returns the value of attribute html.
-
#link ⇒ Object
Returns the value of attribute link.
-
#markdown ⇒ Object
Returns the value of attribute markdown.
-
#permalink ⇒ Object
Returns the value of attribute permalink.
-
#post_id ⇒ Object
Returns the value of attribute post_id.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(item) ⇒ Page
constructor
A new instance of Page.
- #pubdate_to_ruby_time(str) ⇒ Object
Constructor Details
#initialize(item) ⇒ Page
Returns a new instance of Page.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/flee_to_md.rb', line 81 def initialize (item) @title = item.xpath("title").children.to_s @permalink = item.xpath("link").children.to_s date = item.xpath("pubDate").children.to_s @date = pubdate_to_ruby_time(date) @html = item.xpath("content:encoded").children.to_s.slice(9..-4) @markdown = Kramdown::Document.new(@html, :input => 'html').to_kramdown @type = item.xpath("wp:post_type").children.to_s @post_id = item.xpath("wp:post_id").children.to_s @status = item.xpath("wp:status").children.to_s link = item.xpath("wp:postmeta/wp:meta_value").children.to_s if link != "" @type = "linkpost" @link = link end @attachment_url = item.xpath("wp:attachment_url").children.to_s if @attachment_url != "" @attachment_filename = item.xpath("wp:post_name").children.to_s @type = "file" end @categories = [] @tags = [] = item.xpath("category") .each do || kind = .attributes["domain"].children.to_s # "category" or "post_tag" # nickname = meta.attributes["nicename"].to_s # tag or category name proper_name = .children.to_s.slice(9..-4) if kind == "category" @categories.push proper_name # @categories.push({:nickname => nickname, :proper_name => proper_name}) elsif kind == "post_tag" @tags.push proper_name # @tags.push({:nickname => nickname, :proper_name => proper_name}) end end end |
Instance Attribute Details
#attachment_filename ⇒ Object
Returns the value of attribute attachment_filename.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def @attachment_filename end |
#attachment_url ⇒ Object
Returns the value of attribute attachment_url.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def @attachment_url end |
#categories ⇒ Object
Returns the value of attribute categories.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def categories @categories end |
#date ⇒ Object
Returns the value of attribute date.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def date @date end |
#html ⇒ Object
Returns the value of attribute html.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def html @html end |
#link ⇒ Object
Returns the value of attribute link.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def link @link end |
#markdown ⇒ Object
Returns the value of attribute markdown.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def markdown @markdown end |
#permalink ⇒ Object
Returns the value of attribute permalink.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def permalink @permalink end |
#post_id ⇒ Object
Returns the value of attribute post_id.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def post_id @post_id end |
#status ⇒ Object
Returns the value of attribute status.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def status @status end |
#tags ⇒ Object
Returns the value of attribute tags.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
78 79 80 |
# File 'lib/flee_to_md.rb', line 78 def type @type end |
Instance Method Details
#pubdate_to_ruby_time(str) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/flee_to_md.rb', line 117 def pubdate_to_ruby_time (str) pattern = /\w{3}, (\d{2}) (\w{3}) (\d{4}) (\d{2}):(\d{2}):(\d{2}) (\+\d{4})/ match = str.match(pattern) day = match[1] month = match[2] year = match[3] hour = match[4] # weird error: many posts have publish times at 24 oclock. # was causing errors when trying to construct a ruby time object. out of range # what the hell? I'm assuming that means midnight hour = "0" if hour == "24" minute = match[5] second = match[6].to_i offset = match[7].sub(/(\d{2})(\d{2})/,'\1:\2') if RUBY_VERSION.to_f >= 1.9 return Time.new year, month, day, hour, minute, second, offset else return Time.local(year, month, day, hour, minute, second) end end |