Class VocabularyList
In: app/models/vocabulary_list.rb
Parent: ActiveRecord::Base

Methods

Included Modules

KotobaModel

Public Class methods

[Source]

   # File app/models/vocabulary_list.rb, line 5
5:   def self.overview
6:     KotobaModel.overview(self)
7:   end

Public Instance methods

[Source]

    # File app/models/vocabulary_list.rb, line 32
32:   def after_create
33:     VocabularyListsUser.create_owner(self, current_user).save!
34:   end

[Source]

    # File app/models/vocabulary_list.rb, line 72
72:   def authorized_for_create?
73:     return Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_USER)
74:   end

[Source]

    # File app/models/vocabulary_list.rb, line 83
83:   def authorized_for_destroy?
84:     return authorized_for_update?
85:   end

[Source]

    # File app/models/vocabulary_list.rb, line 87
87:   def authorized_for_read?
88:     return Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_USER)
89:   end

[Source]

    # File app/models/vocabulary_list.rb, line 76
76:   def authorized_for_update?
77:     for vocabulary_lists_user in vocabulary_lists_users
78:       return true if vocabulary_lists_user.authorized_for_edit?(current_user)
79:     end
80:     return Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_ADMIN)
81:   end

[Source]

    # File app/models/vocabulary_list.rb, line 36
36:   def to_label
37:     name
38:   end

[Source]

    # File app/models/vocabulary_list.rb, line 40
40:   def to_long_label
41:     # http://b.hatena.ne.jp/entry/3077171/Rubyでマルチバイト文字列からnバイト切り出し%20—%20Weboo!%20Returns.
42:     # http://yamashita.dyndns.org/blog/substring-from-multibyte-string-in-ruby/
43:     #name + ' « ' + description[0..description_length].slice(/\A.{0,}/m) + (description.length > description_length ? '...' : '')
44:     label = name
45:     if description
46:       
47:       description_length = [60, description.length-1].min
48:       begin
49:         label += ' « ' + description[0..description_length] + (description.length > description_length ? '...' : '')      
50:       rescue Exception => exception
51:         logger.error("Unable to postpend the vocabulary list [#{name}] description [#{description}] due to [#{exception}]")
52:         logger.error(exception.backtrace.join("  \n"))
53:       end
54:     end
55:     return label
56:   end

[Source]

    # File app/models/vocabulary_list.rb, line 58
58:   def words_read_only(maximum_words = 150)
59:     words_to_show = Array.new
60:     number_of_words = words.size
61:     words_to_display = [maximum_words, number_of_words].min
62:     words.first(words_to_display).each do |word|
63:       words_to_show << word
64:     end
65:     words_to_show = words_to_show.map do |word|
66:       word.spelling
67:     end
68:     words_to_show <<  "... (#{number_of_words})" if words_to_display < number_of_words
69:     words_to_show.join(', ') << " (#{number_of_words})"
70:   end

[Validate]