Class: Moodle2CC::ResourceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/moodle2cc/resource_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(namespace) ⇒ ResourceFactory

Returns a new instance of ResourceFactory.



3
4
5
# File 'lib/moodle2cc/resource_factory.rb', line 3

def initialize(namespace)
  @namespace = namespace
end

Instance Method Details

#get_resource_from_mod(mod, position = 0) ⇒ Object



7
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
# File 'lib/moodle2cc/resource_factory.rb', line 7

def get_resource_from_mod(mod, position=0)
  case mod.mod_type
  when 'assignment', 'workshop'
    @namespace.const_get(:Assignment).new(mod, position)
  when 'resource'
    case mod.type
    when 'file'
      if mod.summary && mod.summary.length > 0
        @namespace.const_get(:WebContent).new(mod)
      else
        @namespace.const_get(:WebLink).new(mod)
      end
    when 'html', 'text'
      @namespace.const_get(:WebContent).new(mod)
    end
  when 'forum', 'hsuforum'
    @namespace.const_get(:DiscussionTopic).new(mod, position)
  when 'quiz', 'questionnaire', 'choice'
    @namespace.const_get(:Assessment).new(mod, position)
  when 'wiki'
    @namespace.const_get(:Wiki).new(mod)
  when 'label', 'summary'
    html = Nokogiri::HTML(mod.content)
    if html.search('img[src]').length > 0 ||
      html.search('a[href]').length > 0 ||
      html.search('iframe[src]').length > 0 ||
      html.text.strip.length > 200
      @namespace.const_get(:WebContent).new(mod)
    else
      mod.name = html.text.strip
      @namespace.const_get(:Label).new(mod)
    end
  end
end