giri 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/giri/bud.rb +15 -1
- data/lib/giri/context.rb +18 -0
- data/lib/giri/duration.rb +23 -0
- data/lib/giri/text_node_duration.rb +7 -18
- data/lib/giri/version.rb +1 -1
- data/lib/giri.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4941af0601ffb00e81380ca1b6dfe9311f14ad878ab8581e0901e447c47178
|
4
|
+
data.tar.gz: 17effae76955d8b07a554b8e11f17126ee908c8e48b0ca264801150b68f68def
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef4328f59ca11c09302b8275fef6b32338b3043d0306df0a1f6b427fe28b19fde3fb80a3b35d488db6439d941063674762b5a10363b00edf73564d7e63f8cfb7
|
7
|
+
data.tar.gz: 14a27203b15bbdbc4bf043abf6e42960b0d07ab091d42bddf3f374dfdcaaf521bfc4813ef474615832f41bffb24f5e23133adf61364d8d9232216d3ef9ec0811
|
data/lib/giri/bud.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Giri::Bud
|
2
2
|
|
3
3
|
def self.extended(base)
|
4
|
-
base.singleton_class.attr_accessor :xml_nodes, :xml_attributes, :with_name_default_for_node, :with_name_default_for_attribute
|
4
|
+
base.singleton_class.attr_accessor :xml_nodes, :xml_attributes, :context_attributes, :with_name_default_for_node, :with_name_default_for_attribute
|
5
5
|
|
6
6
|
base.xml_nodes = {}
|
7
7
|
base.xml_attributes = []
|
8
|
+
base.context_attributes = []
|
8
9
|
# TODO: Set nil for default
|
9
10
|
base.with_name_default_for_node = :camelize
|
10
11
|
base.with_name_default_for_attribute = :lower_camelcase
|
@@ -38,6 +39,10 @@ module Giri::Bud
|
|
38
39
|
block.call(node)
|
39
40
|
end
|
40
41
|
|
42
|
+
def context
|
43
|
+
@context ||= Giri::Context.new(self)
|
44
|
+
end
|
45
|
+
|
41
46
|
def build_attributes
|
42
47
|
self.class.xml_attributes.map do |col|
|
43
48
|
name = col[:name]
|
@@ -68,6 +73,7 @@ module Giri::Bud
|
|
68
73
|
def inherited(base)
|
69
74
|
base.xml_nodes = xml_nodes.dup
|
70
75
|
base.xml_attributes = xml_attributes.dup
|
76
|
+
base.context_attributes = context_attributes.dup
|
71
77
|
base.with_name_default_for_node = with_name_default_for_node
|
72
78
|
base.with_name_default_for_attribute = with_name_default_for_attribute
|
73
79
|
super
|
@@ -182,4 +188,12 @@ module Giri::Bud
|
|
182
188
|
nil
|
183
189
|
end
|
184
190
|
end
|
191
|
+
|
192
|
+
def context(context_name, &block)
|
193
|
+
self.context_attributes << context_name.to_sym
|
194
|
+
|
195
|
+
class_eval do
|
196
|
+
define_method(context_name, &block)
|
197
|
+
end
|
198
|
+
end
|
185
199
|
end
|
data/lib/giri/context.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Giri::Context
|
2
|
+
def initialize(base_node)
|
3
|
+
@base_node = base_node
|
4
|
+
@context_attributes = base_node.class.context_attributes
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
if @context_attributes.include?(method.to_sym)
|
9
|
+
@base_node.public_send(method, *args, &block)
|
10
|
+
else
|
11
|
+
if @base_node.parent
|
12
|
+
@base_node.parent.context.public_send(method, *args, &block)
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# https://www.w3.org/TR/xmlschema-2/#duration
|
2
|
+
class Giri::Duration < DelegateClass(String)
|
3
|
+
def components
|
4
|
+
@components ||= begin
|
5
|
+
_, years, months, days, time_part, hours, minutes, seconds = self.match(/\AP(\d+Y)?(\d+M)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?\z/).to_a
|
6
|
+
# Example of values "15H" and "15H".to_i will get 15.
|
7
|
+
{
|
8
|
+
years: years.to_i,
|
9
|
+
months: months.to_i,
|
10
|
+
days: days.to_i,
|
11
|
+
hours: hours.to_i,
|
12
|
+
minutes: minutes.to_i,
|
13
|
+
seconds: seconds.to_i,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def duration_time
|
19
|
+
components.reduce(0) do |acc,(k,v)|
|
20
|
+
acc + v.public_send(k)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,24 +1,13 @@
|
|
1
1
|
# https://www.w3.org/TR/xmlschema-2/#duration
|
2
|
-
class Giri::TextNodeDuration < Giri::
|
2
|
+
class Giri::TextNodeDuration < DelegateClass(Giri::Duration)
|
3
|
+
extend Giri::Bud
|
3
4
|
|
4
|
-
def
|
5
|
-
|
6
|
-
_, years, months, days, time_part, hours, minutes, seconds = self.match(/\AP(\d+Y)?(\d+M)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?\z/).to_a
|
7
|
-
# Example of values "15H" and "15H".to_i will get 15.
|
8
|
-
{
|
9
|
-
years: years.to_i,
|
10
|
-
months: months.to_i,
|
11
|
-
days: days.to_i,
|
12
|
-
hours: hours.to_i,
|
13
|
-
minutes: minutes.to_i,
|
14
|
-
seconds: seconds.to_i,
|
15
|
-
}
|
16
|
-
end
|
5
|
+
def self.build_value(str)
|
6
|
+
Giri::Duration.new(str)
|
17
7
|
end
|
18
8
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
end
|
9
|
+
def initialize(*args)
|
10
|
+
initialize_setup(*args)
|
11
|
+
super(self.class.build_value(@node.text))
|
23
12
|
end
|
24
13
|
end
|
data/lib/giri/version.rb
CHANGED
data/lib/giri.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: giri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- metheglin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -62,6 +62,8 @@ files:
|
|
62
62
|
- lib/giri.rb
|
63
63
|
- lib/giri/base_node.rb
|
64
64
|
- lib/giri/bud.rb
|
65
|
+
- lib/giri/context.rb
|
66
|
+
- lib/giri/duration.rb
|
65
67
|
- lib/giri/text_node_big_decimal.rb
|
66
68
|
- lib/giri/text_node_date_time.rb
|
67
69
|
- lib/giri/text_node_duration.rb
|