Class: CanvasAccount

Inherits:
CanvasObject show all
Defined in:
lib/models/canvas_account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CanvasObject

push_csv_to_canvas

Constructor Details

#initialize(opts = {}) ⇒ CanvasAccount

future relase: Make fields reuired by canvas required here



14
15
16
17
18
19
20
21
22
# File 'lib/models/canvas_account.rb', line 14

def initialize(opts = {})
  @name = opts[:name] if opts[:name]
  @uid = opts[:uid] if opts[:uid]
  @parent_id = opts[:parent] if opts[:parent]
  @root_id = opts[:root] if opts[:root]
  @time_zone = opts[:time_zone] if opts[:time_zone]
  @sis_id = opts[:sis] if opts[:sis]
  @workflow = opts[:workflow] if opts[:workflow]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/models/canvas_account.rb', line 3

def name
  @name
end

#parent_uidObject (readonly)

Returns the value of attribute parent_uid.



3
4
5
# File 'lib/models/canvas_account.rb', line 3

def parent_uid
  @parent_uid
end

#root_uidObject (readonly)

Returns the value of attribute root_uid.



3
4
5
# File 'lib/models/canvas_account.rb', line 3

def root_uid
  @root_uid
end

#sis_idObject (readonly)

Returns the value of attribute sis_id.



3
4
5
# File 'lib/models/canvas_account.rb', line 3

def sis_id
  @sis_id
end

#time_zoneObject (readonly)

Returns the value of attribute time_zone.



3
4
5
# File 'lib/models/canvas_account.rb', line 3

def time_zone
  @time_zone
end

#uidObject (readonly)

Returns the value of attribute uid.



3
4
5
# File 'lib/models/canvas_account.rb', line 3

def uid
  @uid
end

#workflowObject (readonly)

Returns the value of attribute workflow.



3
4
5
# File 'lib/models/canvas_account.rb', line 3

def workflow
  @workflow
end

Class Method Details

.gen_file(opts = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/models/canvas_account.rb', line 39

def self.gen_file(opts = {})
  opts[:rows] ? rows = opts[:rows] : rows = 0
  opts[:parent] ? parent = opts[:parent] : parent = 1
  opts[:root] ? root = opts[:root] : root = 1
  accounts = []
  if(opts[:rows])
    rows.times do |x|
      accounts.push(CanvasAccount.random(parent, root))
    end
  end
  header = %w[account_id parent_account_id name status integration_id]
  CSV.open('./accounts.csv', 'wb', write_headers: true, headers: header) do |csv|
    accounts.each do |acc|
      csv << acc.to_csv
    end
  end
  return accounts
end

.random(parent_id = 1, root_id = 1) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/models/canvas_account.rb', line 24

def self.random (parent_id = 1 , root_id = 1)
  a = Forgery('name').company_name
  CanvasAccount.new(
    {
      name: a,
      uid: "#{a}-#{rand(10_000)}",
      parent: parent_id,
      root: root_id,
      time_zone: Forgery('time').zone,
      sis_id: (10_000+rand(10_000_000)),
      workflow: 'active'
      }
    )
end

Instance Method Details

#to_csvObject



9
10
11
# File 'lib/models/canvas_account.rb', line 9

def to_csv
  row = [uid, parent_uid, name, 'active', nil]
end

#to_sObject



5
6
7
# File 'lib/models/canvas_account.rb', line 5

def to_s
  string = "#{name}, #{uid}, #{parent_uid}, #{root_uid}, #{time_zone}, #{sis_id}, #{workflow}"
end