Class: FeedMe::ParserBuilder
- Inherits:
-
Object
- Object
- FeedMe::ParserBuilder
- Defined in:
- lib/feedme.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#atom_entry_tags ⇒ Object
Returns the value of attribute atom_entry_tags.
-
#atom_tags ⇒ Object
Returns the value of attribute atom_tags.
-
#date_tags ⇒ Object
Returns the value of attribute date_tags.
-
#default_transformation ⇒ Object
Returns the value of attribute default_transformation.
-
#ghost_tags ⇒ Object
Returns the value of attribute ghost_tags.
-
#options ⇒ Object
Returns the value of attribute options.
-
#rss_item_tags ⇒ Object
Returns the value of attribute rss_item_tags.
-
#rss_tags ⇒ Object
Returns the value of attribute rss_tags.
-
#transformation_fns ⇒ Object
Returns the value of attribute transformation_fns.
-
#transformations ⇒ Object
Returns the value of attribute transformations.
-
#value_tags ⇒ Object
Returns the value of attribute value_tags.
Instance Method Summary collapse
-
#all_atom_tags ⇒ Object
Prepare tag list for an Atom feed.
-
#all_rss_tags ⇒ Object
Prepare tag list for an RSS feed.
-
#emulate_atom! ⇒ Object
Add aliases so that RSS feed elements can be accessed using the names of their Atom counterparts.
-
#emulate_rss! ⇒ Object
Add aliases so that Atom feed elements can be accessed using the names of their RSS counterparts.
-
#initialize(options = {}) ⇒ ParserBuilder
constructor
A new instance of ParserBuilder.
- #parse(source) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ParserBuilder
Returns a new instance of ParserBuilder.
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/feedme.rb', line 85 def initialize(={}) @options = # rss tags @rss_tags = [ { :image => nil, :textInput => nil, :skipHours => nil, :skipDays => nil, :items => [{ :rdf_Seq => nil }], #:item => @rss_item_tags } ] @rss_item_tags = [ {} ] #atom tags @atom_tags = [ { :author => nil, :contributor => nil, #:entry => @atom_entry_tags } ] @atom_entry_tags = [ { :author => nil, :contributor => nil } ] # tags whose value is a date @date_tags = [ :pubDate, :lastBuildDate, :published, :updated, :dc_date, :expirationDate ] # tags that can be used as the default value for a tag with attributes @value_tags = [ CONTENT_KEY, :href, :url ] # tags that don't become part of the parsed object tree @ghost_tags = [ :rdf_Seq ] # tag/attribute aliases @aliases = { :items => :item_array, :item_array => :entry_array, :entries => :entry_array, :entry_array => :item_array, :link => :'link+self' } # bang mods @default_transformation = [ :stripHtml ] @transformations = {} @transformation_fns = { :stripHtml => proc {|str| # remove all HTML tags str.gsub(/<\/?[^>]*>/, "").strip }, :cleanHtml => proc {|str| # clean HTML content using FeedNormalizer's HtmlCleaner class begin require 'rubygems' require 'feed-normalizer' FeedNormalizer::HtmlCleaner.clean(str) rescue str end }, :wrap => proc {|str, col| # wrap text at a certain number of characters (respecting word boundaries) str.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3\n").strip }, :trunc => proc {|str, wordcount| # truncate text, respecting word boundaries str.trunc(wordcount.to_i) }, :truncHtml => proc {|str, wordcount| # truncate text but leave enclosing HTML tags begin require 'text-helper' TextHelper::truncate_html(str, wordcount.to_i) rescue str end } } end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
80 81 82 |
# File 'lib/feedme.rb', line 80 def aliases @aliases end |
#atom_entry_tags ⇒ Object
Returns the value of attribute atom_entry_tags.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @atom_entry_tags end |
#atom_tags ⇒ Object
Returns the value of attribute atom_tags.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @atom_tags end |
#date_tags ⇒ Object
Returns the value of attribute date_tags.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @date_tags end |
#default_transformation ⇒ Object
Returns the value of attribute default_transformation.
80 81 82 |
# File 'lib/feedme.rb', line 80 def default_transformation @default_transformation end |
#ghost_tags ⇒ Object
Returns the value of attribute ghost_tags.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @ghost_tags end |
#options ⇒ Object
Returns the value of attribute options.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @options end |
#rss_item_tags ⇒ Object
Returns the value of attribute rss_item_tags.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @rss_item_tags end |
#rss_tags ⇒ Object
Returns the value of attribute rss_tags.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @rss_tags end |
#transformation_fns ⇒ Object
Returns the value of attribute transformation_fns.
80 81 82 |
# File 'lib/feedme.rb', line 80 def transformation_fns @transformation_fns end |
#transformations ⇒ Object
Returns the value of attribute transformations.
80 81 82 |
# File 'lib/feedme.rb', line 80 def transformations @transformations end |
#value_tags ⇒ Object
Returns the value of attribute value_tags.
80 81 82 |
# File 'lib/feedme.rb', line 80 def @value_tags end |
Instance Method Details
#all_atom_tags ⇒ Object
Prepare tag list for an Atom feed.
175 176 177 178 179 |
# File 'lib/feedme.rb', line 175 def = .dup [0][:entry] = .dup return end |
#all_rss_tags ⇒ Object
Prepare tag list for an RSS feed.
168 169 170 171 172 |
# File 'lib/feedme.rb', line 168 def = .dup [0][:item] = .dup return end |
#emulate_atom! ⇒ Object
Add aliases so that RSS feed elements can be accessed using the names of their Atom counterparts.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/feedme.rb', line 198 def emulate_atom! aliases.merge!({ :rights => :copyright, :content => :description, :contributor => :author, :id => [ :guid_value, :link ], :author => [ :managingEditor, :webMaster ], :updated => [ :lastBuildDate, :pubDate ], :published => [ :pubDate, :lastBuildDate ], :icon => :'image/url', :logo => :'image/url', :summary => :'description_trunc' }) end |
#emulate_rss! ⇒ Object
Add aliases so that Atom feed elements can be accessed using the names of their RSS counterparts.
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/feedme.rb', line 183 def emulate_rss! aliases.merge!({ :guid => :id, # this alias never actually gets used; see FeedData#id :copyright => :rights, :pubDate => [ :published, :updated ], :lastBuildDate => [ :updated, :published ], :description => [ :content, :summary ], :managingEditor => [ :'author/name', :'contributor/name' ], :webMaster => [ :'author/name', :'contributor/name' ], :image => [ :icon, :logo ] }) end |