Class: Moodle2CC::Moodle2::Models::Label
- Inherits:
-
Object
- Object
- Moodle2CC::Moodle2::Models::Label
- Defined in:
- lib/moodle2cc/moodle2/models/label.rb
Constant Summary collapse
- DEFAULT_PAGE_TITLE =
"Untitled Page"
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#intro ⇒ Object
Returns the value of attribute intro.
-
#intro_format ⇒ Object
Returns the value of attribute intro_format.
-
#module_id ⇒ Object
Returns the value of attribute module_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
- #convert_to_header? ⇒ Boolean
- #convert_to_page? ⇒ Boolean
- #converted_title ⇒ Object
- #intro_html ⇒ Object
- #intro_text ⇒ Object
- #name_text ⇒ Object
- #process_for_conversion! ⇒ Object
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 3 def id @id end |
#intro ⇒ Object
Returns the value of attribute intro.
3 4 5 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 3 def intro @intro end |
#intro_format ⇒ Object
Returns the value of attribute intro_format.
3 4 5 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 3 def intro_format @intro_format end |
#module_id ⇒ Object
Returns the value of attribute module_id.
3 4 5 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 3 def module_id @module_id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 3 def name @name end |
#visible ⇒ Object
Returns the value of attribute visible.
3 4 5 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 3 def visible @visible end |
Instance Method Details
#convert_to_header? ⇒ Boolean
29 30 31 32 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 29 def convert_to_header? process_for_conversion! @convert_to_header end |
#convert_to_page? ⇒ Boolean
24 25 26 27 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 24 def convert_to_page? process_for_conversion! @convert_to_page end |
#converted_title ⇒ Object
19 20 21 22 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 19 def converted_title process_for_conversion! @converted_title end |
#intro_html ⇒ Object
11 12 13 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 11 def intro_html @intro_html ||= (Nokogiri::HTML(@intro.to_s) rescue Nokogiri::HTML('')) end |
#intro_text ⇒ Object
15 16 17 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 15 def intro_text @intro_text ||= (intro_html.text.strip rescue "") end |
#name_text ⇒ Object
7 8 9 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 7 def name_text @name_text ||= (Nokogiri::HTML(@name.to_s).text.strip rescue "") end |
#process_for_conversion! ⇒ Object
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 |
# File 'lib/moodle2cc/moodle2/models/label.rb', line 35 def process_for_conversion! return unless @converted_title.nil? || @convert_to_page.nil? || @convert_to_header.nil? @converted_title = name_text if @converted_title == "Label" || @converted_title.end_with?("...") || @converted_title.length == 0 if intro_text.length > Moodle2CC::Moodle2Converter::ConverterHelper::MAX_TITLE_LENGTH @truncate = true @converted_title = intro_text # we will truncate in the label_converter @convert_to_page = true else if intro_text.length > 0 @converted_title = intro_text else @converted_title = DEFAULT_PAGE_TITLE @convert_to_header = false # if we're not going to convert it to a page, don't convert it at all end end end # if the intro has no text or the text is identical, then convert to page only if it has tags if (@converted_title == intro_text && !@truncate) || intro_text.length == 0 @convert_to_page = intro_html.search('img[src]').length > 0 || intro_html.search('a[href]').length > 0 || intro_html.search('iframe[src]').length > 0 elsif intro_text.length > 0 @convert_to_page = true else @convert_to_page = false end # do the opposite if we haven't already explicitly decided not to convert to a header if @convert_to_header.nil? @convert_to_header = !@convert_to_page end end |