unidom-score 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cfeebbf96334fb6987b64e4e7e3f0381ebf88b4
4
- data.tar.gz: 19b1d37f28aef129b3a1f417a218b018be2a53dd
3
+ metadata.gz: 2c9e9abc9735560e70d40caaaab8208a16dc313e
4
+ data.tar.gz: 455934053a55e4826d4a250de25764f214af6ee8
5
5
  SHA512:
6
- metadata.gz: bc1eb6fbf42fba9c165a2d5016f6263bc1e19419599b56160856930776053290c7977038f52a5cf22e14fc91cfa25de3b0bebc961f28d43528d047511c43d022
7
- data.tar.gz: f84108fd3345b3ca4801ac0a00550dd8eda61cb01641b09f478f5c6bea2670decd053d43855dc8920ed6c56fb91e6c6a7d37c2a4f774318bee22fb5d2a2f0df7
6
+ metadata.gz: b335368d1bddabf333377fefb56a9a72158a66000ddf91f0af06b9ba5fdba0e97d0b7b55815e6277e693e35e48992046774309c58b61c22bc7ec6c6a7d6998e3
7
+ data.tar.gz: 361ff3c5a773d5c322065b6e5cc7dfb12ac6368f267f7f1edec93a589432a3896cb9382d5584d7c62e47c94646a27a0408f525b6c48e02778fa91e070321a40f
data/README.md CHANGED
@@ -36,7 +36,14 @@ The migration versions start with 200601.
36
36
  ## Call the Model
37
37
 
38
38
  ```ruby
39
+ company = Unidom::Party::Company.create! name: 'Xerox'
40
+ template = Unidom::Score::ScoreSheetTemplate.create! subject: company, name: 'Survey 2003', total_score: 100
41
+
39
42
  scorer = Unidom::Party::Person.create! name: 'Tim'
40
43
  score_keeper = Unidom::Party::Shop.create! name: 'WalMart'
41
- score_sheet = Unidom::Score::ScoreSheet.score! scorer: scorer, score_keeper: score_keeper, template: nil, name: nil, score: 98, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
44
+ score_sheet = Unidom::Score::ScoreSheet.score! scorer: scorer, score_keeper: score_keeper, template: template, name: nil, score: 98, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
45
+ # The template could be nil
46
+
47
+ item_1 = Unidom::Score::ScoreItem.score! sheet: score_sheet, scorer: score_sheet.try(:scorer), template: nil, title: template.try(:title), score: 59, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
48
+ item_2 = Unidom::Score::ScoreItem.score! sheet: score_sheet, scorer: score_sheet.try(:scorer), template: nil, title: template.try(:title), score: 39, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
42
49
  ```
@@ -20,8 +20,8 @@ class Unidom::Score::ScoreItem < Unidom::Score::ApplicationRecord
20
20
  scope :template_is, ->(template) { where template_id: to_id(template) }
21
21
  scope :scored_by, ->(scorer) { where scorer: scorer }
22
22
 
23
- def self.score!(sheet: nil, scorer: nil, template: nil, name: template.try(:name), score: 0, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil)
24
- create! sheet: sheet, scorer: scorer, template: template, name: name, score: score, scored_on: scored_on, opened_at: opened_at, description: description, instruction: instruction
23
+ def self.score!(sheet: nil, scorer: sheet.try(:scorer), template: nil, title: template.try(:title), score: 0, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil)
24
+ create! sheet: sheet, scorer: scorer, template: template, title: title, score: score, scored_on: scored_on, opened_at: opened_at, description: description, instruction: instruction
25
25
  end
26
26
 
27
27
  end
@@ -16,7 +16,7 @@ class Unidom::Score::ScoreSheet < Unidom::Score::ApplicationRecord
16
16
  belongs_to :scorer, polymorphic: true
17
17
  belongs_to :score_keeper, polymorphic: true
18
18
 
19
- has_many :score_items, class_name: 'Unidom::Score::ScoreItem'
19
+ has_many :items, class_name: 'Unidom::Score::ScoreItem', foreign_key: :score_sheet_id
20
20
 
21
21
  scope :template_is, ->(template) { where template_id: to_id(template) }
22
22
  scope :scored_by, ->(scorer) { where scorer: scorer }
@@ -0,0 +1,21 @@
1
+ # Score Sheet Tempalte 是评分表模版。
2
+ # #template 是评分表模版。
3
+ # #scorer 是评分者。
4
+ # #score_keeper 是得分者。
5
+
6
+ class Unidom::Score::ScoreSheetTemplate < Unidom::Score::ApplicationRecord
7
+
8
+ self.table_name = 'unidom_score_sheet_templates'
9
+
10
+ include Unidom::Common::Concerns::ModelExtension
11
+
12
+ validates :name, allow_blank: true, length: { in: 2..columns_hash['name'].limit }
13
+ validates :total_score, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
14
+
15
+ belongs_to :subject, polymorphic: true
16
+
17
+ has_many :sheets, class_name: 'Unidom::Score::ScoreSheet'
18
+
19
+ scope :subject_is, ->(subject) { where subject: subject }
20
+
21
+ end
@@ -0,0 +1,30 @@
1
+ class CreateUnidomScoreSheetTemplates < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_score_sheet_templates, id: :uuid do |t|
6
+
7
+ t.references :subject, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+
10
+ t.string :name, null: true, default: nil, limit: 200
11
+ t.decimal :total_score, null: false, default: 0.0, precision: 12, scale: 2
12
+
13
+ t.text :description
14
+ t.text :instruction
15
+
16
+ t.column :state, 'char(1)', null: false, default: 'C'
17
+ t.datetime :opened_at, null: false, default: Time.utc(1970)
18
+ t.datetime :closed_at, null: false, default: Time.utc(3000)
19
+ t.boolean :defunct, null: false, default: false
20
+ t.jsonb :notation, null: false, default: {}
21
+
22
+ t.timestamps null: false
23
+
24
+ end
25
+
26
+ add_index :unidom_score_sheet_templates, :subject_id
27
+
28
+ end
29
+
30
+ end
@@ -26,9 +26,9 @@ class CreateUnidomScoreItems < ActiveRecord::Migration
26
26
 
27
27
  end
28
28
 
29
- add_index :unidom_score_sheets, :score_sheet_id
30
- add_index :unidom_score_sheets, :score_item_template_id
31
- add_index :unidom_score_sheets, :scorer_id
29
+ add_index :unidom_score_items, :score_sheet_id
30
+ add_index :unidom_score_items, :score_item_template_id
31
+ add_index :unidom_score_items, :scorer_id
32
32
 
33
33
  end
34
34
 
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Score
3
- VERSION = '0.2'.freeze
3
+ VERSION = '0.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-score
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2016-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -46,8 +46,10 @@ files:
46
46
  - app/models/unidom/score/application_record.rb
47
47
  - app/models/unidom/score/score_item.rb
48
48
  - app/models/unidom/score/score_sheet.rb
49
+ - app/models/unidom/score/score_sheet_template.rb
49
50
  - app/views/layouts/unidom/score/application.html.erb
50
51
  - config/routes.rb
52
+ - db/migrate/20060101000000_create_unidom_score_sheet_templates.rb
51
53
  - db/migrate/20060111000000_create_unidom_score_sheets.rb
52
54
  - db/migrate/20060112000000_create_unidom_score_items.rb
53
55
  - lib/tasks/score_tasks.rake