feed_yamlizer 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/feed_yamlizer/feed_listener.rb +9 -5
- data/lib/feed_yamlizer/version.rb +1 -1
- metadata +2 -2
@@ -26,23 +26,26 @@ class FeedYamlizer
|
|
26
26
|
@x = {:items => []}
|
27
27
|
end
|
28
28
|
|
29
|
-
def result
|
29
|
+
def result
|
30
|
+
@x
|
31
|
+
end
|
30
32
|
|
31
33
|
def tag_start(name, attrs)
|
32
34
|
@nested_tags.push name
|
33
35
|
case path
|
34
36
|
when 'feed/link'
|
35
|
-
@x[:link]
|
37
|
+
@x[:link] ||= encode attrs['href']
|
36
38
|
when *ITEM_START_TAGS
|
37
39
|
@current_item = {}
|
38
40
|
when 'feed/entry/link'
|
39
|
-
@current_item[:
|
41
|
+
(@current_item[:links] ||= []) << encode(attrs['href'])
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def tag_end(name)
|
44
46
|
case path
|
45
47
|
when *ITEM_START_TAGS
|
48
|
+
@current_item[:link] ||= @current_item[:links].detect {|x| x !~ /\.(jpg|png|gif)$/}
|
46
49
|
@x[:items] << @current_item
|
47
50
|
@current_item = nil
|
48
51
|
end
|
@@ -54,7 +57,7 @@ class FeedYamlizer
|
|
54
57
|
when *FEED_TITLE_TAGS
|
55
58
|
@x[:title] = encode text.strip
|
56
59
|
when *FEED_LINK_TAGS
|
57
|
-
@x[:link]
|
60
|
+
@x[:link] ||= encode text.strip
|
58
61
|
when *ITEM_TITLE_TAGS
|
59
62
|
@current_item[:title] = encode(text.strip)
|
60
63
|
when *ITEM_AUTHOR_TAGS
|
@@ -64,7 +67,8 @@ class FeedYamlizer
|
|
64
67
|
when *ITEM_PUB_DATE_TAGS
|
65
68
|
@current_item[:pub_date] = DateTime.parse(encode(text))
|
66
69
|
when *ITEM_LINK_TAGS
|
67
|
-
@current_item[:link]
|
70
|
+
@current_item[:link] ||= encode(text)
|
71
|
+
(@current_item[:links] ||= []) << encode(text)
|
68
72
|
when *ITEM_SUMMARY_TAGS
|
69
73
|
if @current_item[:summary]
|
70
74
|
@current_item[:summary] << encode(text)
|