Class: Article
- Inherits:
-
Object
- Object
- Article
- Defined in:
- lib/vrtx/article.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#hpricotItem ⇒ Object
Returns the value of attribute hpricotItem.
-
#url ⇒ Object
Returns the value of attribute url.
-
#vortexResourceType ⇒ Object
readonly
Returns the value of attribute vortexResourceType.
Instance Method Summary collapse
-
#basename ⇒ Object
Returns basename of the url for article.
-
#dirname ⇒ Object
Returns url without filname for articles.
-
#initialize(*args) ⇒ Article
constructor
A new instance of Article.
- #inspect ⇒ Object
- #method_missing(method_name, *args) ⇒ Object
-
#put! ⇒ Object
Puts the article to the server.
- #update ⇒ Object
-
#visualProfile ⇒ Object
Boolean method that returns true if visualProfile is enabled.
-
#visualProfile=(value) ⇒ Object
Set the visualProfile.
Constructor Details
#initialize(*args) ⇒ Article
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
# File 'lib/vrtx/article.rb', line 8 def initialize(*args) @url = args[0] if(@url =~ /:\/\/[^\/]*dav\./)then item = WebDAV.propfind(url) @vortexResourceType = item.property("v:resourceType") if(vortexResourceType)then if(@vortexResourceType == "article")then # do nothing. no conversion necessary @hpricotElem = item @content = WebDAV.get(@url) end if(@vortexResourceType == "nyhet")then puts "TODO: Manipulate xml of propierties so it becomes an article instead" @hpricotElem = item @hpricotElem.search("v:resourceType").remove puts "class" + @hpricotElem.class.to_s element = @hpricotElem.search("d:displayname") element.after "<v:resourceType xmlns:v=\"vrtx\">article</v:resourceType>" title = item.property("v:title") element.after "<v:userTitle xmlns:v=\"vrtx\">#{title}</v:userTitle>" @hpricotElem.search("tittel").remove publishedDate = @hpricotElem.at("dato").inner_text puts "TODO: Scrape url" end if(@vortexResourceType == "managed-xml")then @hpricotElem = item # HTML must be scraped off publicUrl = Vortex.davUrl2webUrl(@url) require 'open-uri' puts "DEBUG: scraping content..." content = "" open(publicUrl) { |f| content=f.read } puts content puts "---------" doc = Hpricot(open(publicUrl)) # Make sure we can scrape content, even if content is password protected... # Må logge inn curl_get_cmd = "curl ..." # @content = doc.searchWebDAV.get(@url) end # TODO If @vortexResourceType is not recognized, read content end if(item.collection)then @hpricotElem = item @collection = true end else puts "Warning: Not WebDAV url: " + @url end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vrtx/article.rb', line 73 def method_missing(method_name, *args) # TODO Detect attribute writers: article.createdBy = thomasfl # puts "DEBUG: Article." + method_name.to_s + "() method missing" if(@hpricotElem)then result = @hpricotElem.method_missing(method_name, *args) end if(result == nil)then puts "Warning: Article." + method_name.to_s + "() method missing returns nil" end if(result == "false")then return false end return result end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'lib/vrtx/article.rb', line 5 def content @content end |
#hpricotItem ⇒ Object
Returns the value of attribute hpricotItem.
5 6 7 |
# File 'lib/vrtx/article.rb', line 5 def hpricotItem @hpricotItem end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/vrtx/article.rb', line 5 def url @url end |
#vortexResourceType ⇒ Object (readonly)
Returns the value of attribute vortexResourceType.
6 7 8 |
# File 'lib/vrtx/article.rb', line 6 def vortexResourceType @vortexResourceType end |
Instance Method Details
#basename ⇒ Object
Returns basename of the url for article
90 91 92 |
# File 'lib/vrtx/article.rb', line 90 def basename return File.basename(@url) end |
#dirname ⇒ Object
Returns url without filname for articles
95 96 97 |
# File 'lib/vrtx/article.rb', line 95 def dirname return File.dirname(@url) + "/" end |
#inspect ⇒ Object
202 203 204 |
# File 'lib/vrtx/article.rb', line 202 def inspect "Article. URL: " + @url end |
#put! ⇒ Object
Puts the article to the server
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/vrtx/article.rb', line 125 def put!() # Publiser en artikkel med eventuelle justeringen. puts "put!: @vortexResourceType: '" + @vortexResourceType + "'" item = @hpricotElem if(@vortexResourceType == "nyhet")then # This conversion should be done when article is read!!! end if(@vortexResourceType == "managed-xml")then # This conversion should be done when article is read!!! = { # :authors => item.authors.strip!, # FIXME: Support multiple authors :characterEncoding => item.characterEncoding.downcase, :creationDate => item.creationDate, :contentLastModified => item.contentLastModified, :propertiesLastModified => item.propertiesLastModified, :owner => item.owner, :propertiesModifiedBy => item.propertiesModifiedBy, :createdBy => item.createdBy, :contentModifiedBy => item.contentModifiedBy } require 'pp' end if(@vortexResourceType == "article")then = { :authors => item..strip!, # FIXME: Support multiple authors :characterEncoding => item.characterEncoding, :creationDate => item.creationDate, :contentLastModified => item.contentLastModified, :propertiesLastModified => item.propertiesLastModified, :owner => item.owner, :propertiesModifiedBy => item.propertiesModifiedBy, :createdBy => item.createdBy, :contentModifiedBy => item.contentModifiedBy } end begin visualProfile = (not item.property("disabled") == "true") # puts "item.visualProfile: '" + item.visualProfile.to_s + "'" if(not(visualProfile )) .merge!(:visualProfile => false) end # require 'pp' # pp options url = @url title = item.title introduction = item.introduction content = @content published_date = item.property("published-date") puts "PUT url:" + url # puts "title:"+ title # puts "introduction:" + introduction.strip! # puts "content:\n------------\n:" + content + "\n--end------" # puts "pbulished-date:" + published_date # , options) # Vortex.publish_article(url, title, introduction, content, published_date, options) end end |
#update ⇒ Object
198 199 200 |
# File 'lib/vrtx/article.rb', line 198 def update() # Proppatch end |
#visualProfile ⇒ Object
Boolean method that returns true if visualProfile is enabled.
101 102 103 104 105 106 |
# File 'lib/vrtx/article.rb', line 101 def visualProfile # Vortex default behaviour is visualProfile is always turned on # and propfind only return the property <disabled ...> if # visualProfile is disabled. return (not @hpricotElem.property("disabled") == "true") end |
#visualProfile=(value) ⇒ Object
Set the visualProfile. Value must be boolean
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vrtx/article.rb', line 109 def visualProfile=(value) # Sets the visualProfile property by modifying the xml properties if(value.class == TrueClass or value.class == FalseClass ) then if(value == true)then if(@hpricotElem.search("disabled"))then @hpricotElem.search("disabled").remove end end if(value == false)then element = @hpricotElem.search("d:displayname") element.after "<disabled xmlns=\"http://www.uio.no/visual-profile\">true</disabled>" end end end |