Class: Senkyoshi::ContentFile
- Defined in:
- lib/senkyoshi/models/content_file.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#linkname ⇒ Object
readonly
Returns the value of attribute linkname.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.clean_xid(xid) ⇒ Object
Remove leading slash if necessary so that ContentFile.name will match the Senkyoshi.xid.
- .correct_linkname(canvas_file) ⇒ Object
Instance Method Summary collapse
- #canvas_conversion(resources, canvas_file = nil) ⇒ Object
-
#initialize(xml) ⇒ ContentFile
constructor
A new instance of ContentFile.
Methods inherited from Resource
#_find_directories, #_fix_path, #_matches_directory_xid?, #_search_and_replace, #cleanup, #fix_html, get_pre_data, #matches_xid?, #strip_xid
Constructor Details
#initialize(xml) ⇒ ContentFile
Returns a new instance of ContentFile.
7 8 9 10 11 |
# File 'lib/senkyoshi/models/content_file.rb', line 7 def initialize(xml) @id = xml.xpath("./@id").first.text @linkname = xml.xpath("./LINKNAME/@value").first.text @name = ContentFile.clean_xid xml.xpath("./NAME").first.text end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/senkyoshi/models/content_file.rb', line 5 def id @id end |
#linkname ⇒ Object (readonly)
Returns the value of attribute linkname.
5 6 7 |
# File 'lib/senkyoshi/models/content_file.rb', line 5 def linkname @linkname end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/senkyoshi/models/content_file.rb', line 5 def name @name end |
Class Method Details
.clean_xid(xid) ⇒ Object
Remove leading slash if necessary so that ContentFile.name will match the Senkyoshi.xid
17 18 19 20 21 22 23 |
# File 'lib/senkyoshi/models/content_file.rb', line 17 def self.clean_xid(xid) if xid.start_with? "/" xid[1..-1] else xid end end |
.correct_linkname(canvas_file) ⇒ Object
25 26 27 |
# File 'lib/senkyoshi/models/content_file.rb', line 25 def self.correct_linkname(canvas_file) canvas_file.file_path.split("/").last end |
Instance Method Details
#canvas_conversion(resources, canvas_file = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/senkyoshi/models/content_file.rb', line 29 def canvas_conversion(resources, canvas_file = nil) path = if canvas_file canvas_file.file_path else resource = resources.detect_xid(@name) resource.path if resource end query = "?canvas_download=1&canvas_qs_wrap=1" href = "#{FILE_BASE}/#{path}#{query}" %{ <a class="instructure_scribd_file instructure_file_link" title="#{@linkname}" href="#{href}"> #{@linkname} </a> } end |