dina 0.7.3.0 → 0.7.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06235bf5d722c2f96bbbc1d4c4bd3dd7e78bc1eef08c0e9e7412c6920312c17b
4
- data.tar.gz: 4bd30f51b2626a453e1871dab175057869be4d6bd15d00817cf835ff6ec89d00
3
+ metadata.gz: 620e59a87be3c3adb55fba2d7d4084a12fbb12a78427ca53de33426ae8510110
4
+ data.tar.gz: 6c2c5daff310c35f43b165156fc06944d44e4a74db84da12af055fb4d0be401d
5
5
  SHA512:
6
- metadata.gz: d25fecef73f0669268ab5e52e29b935b5e42447988aff67e48489f9b46aec181ab05fde556460384ceab61ca1ecdf9d55e7049d43610f53c6e044091eefba1db
7
- data.tar.gz: a8a9e55dd08583d371a47e1fe1004e1003edd844a866ddc51bcc6b6ec5c150f5e57814c024d18a14464c63787bbc158e079e27f8acfc55ee6fb9f7a7c2dd84ed
6
+ metadata.gz: 3b5913b6fe291bbcb26b4c5bf298bf4f6307077e006442952ad1937833952074728352cc1f0e1e01a6abfa8f5197b06161ddf1ef674dc29a4012761f46ed231a
7
+ data.tar.gz: dea42bb62339358120b3d890edd22727c81058e30e6b9b3c7443d90e515e10942a12533bc94e52b5d8a6a8578d1ba67e70e6c4e1366672c828a789c1bace37e0
@@ -6,31 +6,16 @@ module Dina
6
6
  @descriptions = []
7
7
  if opts[:descriptions]
8
8
  @descriptions = opts[:descriptions]
9
- end
10
- if opts[:english]
11
- self.english_description = opts[:english]
12
- end
13
- if opts[:french]
14
- self.french_description = opts[:french]
9
+ else
10
+ self.set_description(opts)
15
11
  end
16
12
  end
17
13
 
18
- def english_description=(desc)
19
- descriptions.delete_if{|o| o[:lang] == "en"}
20
- descriptions << { lang: "en", desc: desc }
21
- end
22
-
23
- def english_description
24
- descriptions.select{|o| o[:lang] == "en"}.first[:desc]
25
- end
26
-
27
- def french_description=(desc)
28
- descriptions.delete_if{|o| o[:lang] == "fr"}
29
- descriptions << { lang: "fr", desc: desc }
30
- end
31
-
32
- def french_description
33
- descriptions.select{|o| o[:lang] == "fr"}.first[:desc]
14
+ def set_description(opts = {})
15
+ opts.each do |key, value|
16
+ descriptions.delete_if{|o| o[:lang] == key.to_s}
17
+ descriptions << { lang: key.to_s, desc: value }
18
+ end
34
19
  end
35
20
 
36
21
  def to_hash
@@ -4,7 +4,7 @@ module Dina
4
4
  class MultilingualDescriptionCaster
5
5
  def self.cast(value, default)
6
6
  begin
7
- Dina::MultilingualDescription.new(value).to_hash
7
+ MultilingualDescription.new(value).to_hash
8
8
  rescue ArgumentError
9
9
  { descriptions: [] }
10
10
  end
@@ -6,31 +6,16 @@ module Dina
6
6
  @titles = []
7
7
  if opts[:titles]
8
8
  @titles = opts[:titles]
9
- end
10
- if opts[:english]
11
- self.english_title = opts[:english]
12
- end
13
- if opts[:french]
14
- self.french_title = opts[:french]
9
+ else
10
+ self.set_title(opts)
15
11
  end
16
12
  end
17
13
 
18
- def english_title=(title)
19
- titles.delete_if{|o| o[:lang] == "en"}
20
- titles << { lang: "en", title: title }
21
- end
22
-
23
- def english_title
24
- titles.select{|o| o[:lang] == "en"}.first[:title]
25
- end
26
-
27
- def french_title=(title)
28
- titles.delete_if{|o| o[:lang] == "fr"}
29
- titles << { lang: "fr", title: title }
30
- end
31
-
32
- def french_title
33
- titles.select{|o| o[:lang] == "fr"}.first[:title]
14
+ def set_title(opts ={})
15
+ opts.each do |key, value|
16
+ titles.delete_if{|o| o[:lang] == key.to_s}
17
+ titles << { lang: key.to_s, title: value }
18
+ end
34
19
  end
35
20
 
36
21
  def to_hash
@@ -4,7 +4,7 @@ module Dina
4
4
  class MultilingualTitleCaster
5
5
  def self.cast(value, default)
6
6
  begin
7
- Dina::MultilingualTitle.new(value).to_hash
7
+ MultilingualTitle.new(value).to_hash
8
8
  rescue ArgumentError
9
9
  { titles: [] }
10
10
  end
@@ -4,5 +4,6 @@ module Dina
4
4
  class TokenStoreContentInvalid < DinaException; end
5
5
  class ConfigItemMissing < DinaException; end
6
6
  class ObjectInvalid < DinaException; end
7
+ class PropertyInvalid < ObjectInvalid; end
7
8
  class PropertyValueInvalid < ObjectInvalid; end
8
9
  end
@@ -40,15 +40,37 @@ module Dina
40
40
  super
41
41
  end
42
42
 
43
- def english_description
43
+ # Adds or updates a multilingualDescription with a language key
44
+ #
45
+ # @param opts [Hash] the description expessed as { en: "My description" }
46
+ def set_multilingualDescription(opts = {})
44
47
  if self.respond_to?(:multilingualDescription)
45
- multilingualDescription[:descriptions].select{|o| o[:lang] == "en"}.first[:desc]
48
+ if self.multilingualDescription.nil?
49
+ self.multilingualDescription = opts
50
+ else
51
+ descriptions = multilingualDescription["descriptions"]
52
+ descriptions.delete_if{|o| o["lang"] == opts.keys[0].to_s}
53
+ descriptions << { "lang" => opts.keys[0].to_s, "desc" => opts[opts.keys[0]] }
54
+ end
55
+ else
56
+ raise PropertyInvalid, "#{self.class} does not have the property multilingualDescription"
46
57
  end
47
58
  end
48
59
 
49
- def french_description
50
- if self.respond_to?(:multilingualDescription)
51
- multilingualDescription[:descriptions].select{|o| o[:lang] == "fr"}.first[:desc]
60
+ # Adds or updates a multilingualTitle with a language key
61
+ #
62
+ # @param opts [Hash] the title expessed as { en: "My title" }
63
+ def set_multilingualTitle(opts = {})
64
+ if self.respond_to?(:multilingualTitle)
65
+ if self.multilingualTitle.nil?
66
+ self.multilingualTitle = opts
67
+ else
68
+ titles = multilingualTitle["titles"]
69
+ titles.delete_if{|o| o["lang"] == opts.keys[0].to_s}
70
+ titles << { "lang" => opts.keys[0].to_s, "title" => opts[opts.keys[0]] }
71
+ end
72
+ else
73
+ raise PropertyInvalid, "#{self.class} does not have the property multilingualTitle"
52
74
  end
53
75
  end
54
76
 
@@ -46,22 +46,6 @@ module Dina
46
46
  ]
47
47
  end
48
48
 
49
- def english_description=(desc)
50
- description[:en] = desc
51
- end
52
-
53
- def english_description
54
- description[:en]
55
- end
56
-
57
- def french_description=(desc)
58
- description[:fr] = desc
59
- end
60
-
61
- def french_description
62
- description[:fr]
63
- end
64
-
65
49
  private
66
50
 
67
51
  def on_before_save
data/lib/dina/version.rb CHANGED
@@ -3,7 +3,7 @@ module Dina
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- PATCH = 3
6
+ PATCH = 4
7
7
  BUILD = 0
8
8
 
9
9
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3.0
4
+ version: 0.7.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David P. Shorthouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2023-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client