code-ruby 3.0.3 → 3.0.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/object/ics.rb +24 -4
- data/lib/code/object/string.rb +6 -2
- data/spec/code/object/ics_spec.rb +50 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a1d60879ca94a53452e814d8c8de4975be88088beb0ce216f3584a48b0dfcae
|
|
4
|
+
data.tar.gz: 0ad78db73acc96f99df57e3c945c5d97fb404ed692d5f9de7c7bc08c25562468
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2eec31b74d22e1d123ea138cf41063792cbff5e2192e26a692c7dfaa52834db9112bacb9929d3a88d59a6fd4296cc23ff0501a41761f95fa963b027878eda54c
|
|
7
|
+
data.tar.gz: 3363b4f05ca9203842aa8c3a6eee0ccd2ac570609cd9bf3bfb77bda134b234c2ddd0e95a9265941ac8239659260823dfc8e36c8fb34643d835cc702dbc5e5ae4
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.0.
|
|
1
|
+
3.0.4
|
data/lib/code/object/ics.rb
CHANGED
|
@@ -46,7 +46,14 @@ class Code
|
|
|
46
46
|
next unless event.respond_to?(attribute)
|
|
47
47
|
|
|
48
48
|
serialized = serialize_value(event.public_send(attribute))
|
|
49
|
-
serialized =
|
|
49
|
+
serialized =
|
|
50
|
+
if attribute == :categories && serialized.is_a?(::Array)
|
|
51
|
+
serialized.flatten(1)
|
|
52
|
+
elsif scalar_event_attribute?(attribute) && serialized.is_a?(::Array)
|
|
53
|
+
serialized.join(",")
|
|
54
|
+
else
|
|
55
|
+
serialized
|
|
56
|
+
end
|
|
50
57
|
result[attribute] = serialized unless serialized.nil?
|
|
51
58
|
end.merge(
|
|
52
59
|
timestamp: serialize_value(event.dtstamp),
|
|
@@ -60,7 +67,9 @@ class Code
|
|
|
60
67
|
case value
|
|
61
68
|
when nil
|
|
62
69
|
nil
|
|
63
|
-
when ::String
|
|
70
|
+
when ::String
|
|
71
|
+
normalize_string(value)
|
|
72
|
+
when ::Symbol, ::Integer, ::Float, ::BigDecimal, true, false
|
|
64
73
|
value
|
|
65
74
|
when ::Array
|
|
66
75
|
value.map { |item| serialize_value(item) }
|
|
@@ -73,13 +82,24 @@ class Code
|
|
|
73
82
|
if value.respond_to?(:value)
|
|
74
83
|
serialize_value(value.value)
|
|
75
84
|
elsif value.respond_to?(:to_ical)
|
|
76
|
-
value.to_ical
|
|
85
|
+
normalize_string(value.to_ical)
|
|
77
86
|
else
|
|
78
|
-
value.to_s
|
|
87
|
+
normalize_string(value.to_s)
|
|
79
88
|
end
|
|
80
89
|
end
|
|
81
90
|
end
|
|
82
91
|
|
|
92
|
+
def self.scalar_event_attribute?(attribute)
|
|
93
|
+
!%i[categories attendees geo].include?(attribute)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.normalize_string(value)
|
|
97
|
+
value
|
|
98
|
+
.dup
|
|
99
|
+
.force_encoding(::Encoding::UTF_8)
|
|
100
|
+
.encode(::Encoding::UTF_8, invalid: :replace, undef: :replace)
|
|
101
|
+
end
|
|
102
|
+
|
|
83
103
|
def self.serialize_date_like(value)
|
|
84
104
|
case value
|
|
85
105
|
when ::Time, ::Date, ::ActiveSupport::TimeWithZone
|
data/lib/code/object/string.rb
CHANGED
|
@@ -74,7 +74,7 @@ class Code
|
|
|
74
74
|
sig(args)
|
|
75
75
|
code_strip
|
|
76
76
|
when "split"
|
|
77
|
-
sig(args) { String }
|
|
77
|
+
sig(args) { String.maybe }
|
|
78
78
|
code_split(code_value)
|
|
79
79
|
else
|
|
80
80
|
super
|
|
@@ -162,7 +162,11 @@ class Code
|
|
|
162
162
|
def code_split(value)
|
|
163
163
|
code_value = value.to_code
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
if code_value.nothing?
|
|
166
|
+
List.new(raw.split)
|
|
167
|
+
else
|
|
168
|
+
List.new(raw.split(code_value.to_s))
|
|
169
|
+
end
|
|
166
170
|
end
|
|
167
171
|
|
|
168
172
|
def present?
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Code::Object::Ics do
|
|
6
|
+
it "normalizes binary event strings before json serialization" do
|
|
7
|
+
source =
|
|
8
|
+
<<~ICS
|
|
9
|
+
BEGIN:VCALENDAR
|
|
10
|
+
VERSION:2.0
|
|
11
|
+
PRODID:-//code-ruby//EN
|
|
12
|
+
BEGIN:VEVENT
|
|
13
|
+
UID:event-1
|
|
14
|
+
DTSTART:20260327T120000Z
|
|
15
|
+
DTEND:20260327T133000Z
|
|
16
|
+
SUMMARY:Joséphine
|
|
17
|
+
DESCRIPTION:https://luma.com/opv3owre
|
|
18
|
+
END:VEVENT
|
|
19
|
+
END:VCALENDAR
|
|
20
|
+
ICS
|
|
21
|
+
|
|
22
|
+
events = described_class.code_parse(Code::Object::String.new(source.b))
|
|
23
|
+
|
|
24
|
+
expect { expect(events.to_json).to include("Joséphine") }.not_to output.to_stderr
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "serializes comma-separated descriptions as strings" do
|
|
28
|
+
source =
|
|
29
|
+
<<~ICS
|
|
30
|
+
BEGIN:VCALENDAR
|
|
31
|
+
VERSION:2.0
|
|
32
|
+
PRODID:-//code-ruby//EN
|
|
33
|
+
BEGIN:VEVENT
|
|
34
|
+
UID:event-2
|
|
35
|
+
DTSTART:20260401T170000Z
|
|
36
|
+
DTEND:20260401T190000Z
|
|
37
|
+
SUMMARY:Le Cirque du Donut
|
|
38
|
+
DESCRIPTION:Bonjour Paris !\\nLe 1er avril, Kate Raworth vous donne rendez-vous, pour une soirée inédite.
|
|
39
|
+
END:VEVENT
|
|
40
|
+
END:VCALENDAR
|
|
41
|
+
ICS
|
|
42
|
+
|
|
43
|
+
events = described_class.code_parse(Code::Object::String.new(source))
|
|
44
|
+
description = events.raw.first.code_get("description").raw
|
|
45
|
+
|
|
46
|
+
expect(description).to be_a(String)
|
|
47
|
+
expect(description).to include("Le 1er avril, Kate Raworth")
|
|
48
|
+
expect(description).to include("rendez-vous, pour")
|
|
49
|
+
end
|
|
50
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: code-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Marié
|
|
@@ -321,6 +321,7 @@ files:
|
|
|
321
321
|
- spec/code/object/decimal_spec.rb
|
|
322
322
|
- spec/code/object/dictionary_spec.rb
|
|
323
323
|
- spec/code/object/function_spec.rb
|
|
324
|
+
- spec/code/object/ics_spec.rb
|
|
324
325
|
- spec/code/object/integer_spec.rb
|
|
325
326
|
- spec/code/object/list_spec.rb
|
|
326
327
|
- spec/code/object/nothing_spec.rb
|