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.
22 23 24 25 26 |
# File 'lib/senkyoshi/models/content_file.rb', line 22 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.
20 21 22 |
# File 'lib/senkyoshi/models/content_file.rb', line 20 def id @id end |
#linkname ⇒ Object (readonly)
Returns the value of attribute linkname.
20 21 22 |
# File 'lib/senkyoshi/models/content_file.rb', line 20 def linkname @linkname end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/senkyoshi/models/content_file.rb', line 20 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
32 33 34 35 36 37 38 |
# File 'lib/senkyoshi/models/content_file.rb', line 32 def self.clean_xid(xid) if xid.start_with? "/" xid[1..-1] else xid end end |
.correct_linkname(canvas_file) ⇒ Object
40 41 42 |
# File 'lib/senkyoshi/models/content_file.rb', line 40 def self.correct_linkname(canvas_file) canvas_file.file_path.split("/").last end |
Instance Method Details
#canvas_conversion(resources, canvas_file = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/senkyoshi/models/content_file.rb', line 44 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 |