Class: Tabcast::TabCastFeed

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, format) ⇒ TabCastFeed

Returns a new instance of TabCastFeed.



27
28
29
30
31
32
33
# File 'lib/tabcast.rb', line 27

def initialize(url, format)
	@url = url
	@feed  = RSS::Parser.parse(url, false)
	@template = Liquid::Template.parse(unescape(format))
	@killlist = []
	@guidkilllist = []
end

Instance Attribute Details

#feedObject (readonly)

Returns the value of attribute feed.



24
25
26
# File 'lib/tabcast.rb', line 24

def feed
  @feed
end

#prefixObject

Returns the value of attribute prefix.



24
25
26
# File 'lib/tabcast.rb', line 24

def prefix
  @prefix
end

#suffixObject

Returns the value of attribute suffix.



24
25
26
# File 'lib/tabcast.rb', line 24

def suffix
  @suffix
end

#templateObject (readonly)

Returns the value of attribute template.



24
25
26
# File 'lib/tabcast.rb', line 24

def template
  @template
end

#urlObject (readonly)

Returns the value of attribute url.



24
25
26
# File 'lib/tabcast.rb', line 24

def url
  @url
end

Instance Method Details

#formattedObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
# File 'lib/tabcast.rb', line 43

def formatted
vars = {}

vars['channel_title'] 		= @feed.channel.title 		if @feed.channel.title
vars['channel_description'] 	= @feed.channel.description 	if @feed.channel.description
vars['channel_link'] 		= @feed.channel.link 		if @feed.channel.link
vars['channel_language']	= @feed.channel.language 	if @feed.channel.language

string = ""
string += @prefix.render(vars) 
	@feed.items.each do |i|
		if i.enclosure && i.enclosure.url
			if @killlist.include? i.enclosure.url
				killed = true
			end
		else
			killed = true
		end
		
		if i.guid
			if @guidkilllist.include? i.guid.to_s
				killed = true
			end
		end
		#killed = true if i.guid && (@guidkilllist.include? i.guid.to_s)
			
		unless killed
			if i.pubDate
				vars['utime'] = i.pubDate.strftime('%s') 
			else
				vars['utime'] = nil
			end

			if i.title
				vars['title'] = i.title.chomp
			else
				vars['title'] = nil
			end
			
			if i.enclosure && i.enclosure.url
				vars['enclosure_url'] = i.enclosure.url
			else
				vars['enclosure_url'] = nil
			end
			
			if i.itunes_author
				vars['itunes_author'] = i.itunes_author if i.itunes_author
			else
				vars['itunes_author'] = nil
			end

			if i.author
				vars['author'] = i.author
			else
				vars['guid'] = nil
			end
	
			string += @template.render(vars)
		end
	end
	string += @suffix.render(vars)
	string
end

#guidkillfile=(filename) ⇒ Object



111
112
113
# File 'lib/tabcast.rb', line 111

def guidkillfile=(filename)
	@guidkilllist = File.read(File.expand_path(filename)).split("\n")
end

#killfile=(filename) ⇒ Object



107
108
109
# File 'lib/tabcast.rb', line 107

def killfile=(filename)
	@killlist = File.read(File.expand_path(filename)).split("\n")
end