Class: Immigrada::BloggerEntry
- Inherits:
-
Object
- Object
- Immigrada::BloggerEntry
- Defined in:
- lib/immigrada/blogger_entry.rb
Overview
Class for parsing post data from entry XML object.
Instance Method Summary collapse
-
#content ⇒ Object
Returns string with entry HTML content.
-
#initialize(entry_xml) ⇒ BloggerEntry
constructor
A new instance of BloggerEntry.
-
#post? ⇒ Boolean
Check if entry is post.
-
#published ⇒ Object
Returns string with published date.
-
#slug ⇒ Object
Returns string with entry slug.
-
#tags ⇒ Object
Returns array of entry tags.
-
#title ⇒ Object
Returns string with entry title.
Constructor Details
#initialize(entry_xml) ⇒ BloggerEntry
Returns a new instance of BloggerEntry.
5 6 7 |
# File 'lib/immigrada/blogger_entry.rb', line 5 def initialize(entry_xml) @entry_xml = entry_xml end |
Instance Method Details
#content ⇒ Object
Returns string with entry HTML content.
43 44 45 46 47 |
# File 'lib/immigrada/blogger_entry.rb', line 43 def content @entry_xml .search("content[@type='html']") .text end |
#post? ⇒ Boolean
Check if entry is post.
50 51 52 53 54 55 |
# File 'lib/immigrada/blogger_entry.rb', line 50 def post? @entry_xml .search('id') .text .include?('post') end |
#published ⇒ Object
Returns string with published date.
17 18 19 20 21 22 23 24 25 |
# File 'lib/immigrada/blogger_entry.rb', line 17 def published raw_date = @entry_xml .search('published') .text Date .parse(raw_date) .strftime('%Y-%m-%d') .to_s end |
#slug ⇒ Object
Returns string with entry slug.
35 36 37 38 39 40 |
# File 'lib/immigrada/blogger_entry.rb', line 35 def slug link = @entry_xml .search("link[@rel='alternate']") .first['href'] File.basename(link, File.extname(link)) end |
#tags ⇒ Object
Returns array of entry tags.
28 29 30 31 32 |
# File 'lib/immigrada/blogger_entry.rb', line 28 def @entry_xml .search('category[@scheme=\'http://www.blogger.com/atom/ns#\']') .map { |c| c['term'] } end |
#title ⇒ Object
Returns string with entry title.
10 11 12 13 14 |
# File 'lib/immigrada/blogger_entry.rb', line 10 def title @entry_xml .search('title') .text end |