Class: Immigrada::BloggerEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/immigrada/blogger_entry.rb

Overview

Class for parsing post data from entry XML object.

Instance Method Summary collapse

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

#contentObject

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.

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/immigrada/blogger_entry.rb', line 50

def post?
  @entry_xml
    .search('id')
    .text
    .include?('post')
end

#publishedObject

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

#slugObject

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

#tagsObject

Returns array of entry tags.



28
29
30
31
32
# File 'lib/immigrada/blogger_entry.rb', line 28

def tags
  @entry_xml
    .search('category[@scheme=\'http://www.blogger.com/atom/ns#\']')
    .map { |c| c['term'] }
end

#titleObject

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