kdl 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module KDL
2
+ module Types
3
+ class UUID < Value
4
+ RGX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
5
+
6
+ def self.call(value, type = 'uuid')
7
+ return nil unless value.is_a? ::KDL::Value::String
8
+
9
+ uuid = value.value.downcase
10
+ raise ArgumentError, "`#{value.value}' is not a valid uuid" unless uuid =~ RGX
11
+
12
+ new(uuid, type: type)
13
+ end
14
+ end
15
+ MAPPING['uuid'] = UUID
16
+ end
17
+ end
data/lib/kdl/types.rb ADDED
@@ -0,0 +1,22 @@
1
+ module KDL
2
+ module Types
3
+ MAPPING = {}
4
+ end
5
+ end
6
+
7
+ require 'kdl/types/date_time'
8
+ require 'kdl/types/duration'
9
+ require 'kdl/types/currency'
10
+ require 'kdl/types/country'
11
+ require 'kdl/types/ip'
12
+ require 'kdl/types/url'
13
+ require 'kdl/types/uuid'
14
+ require 'kdl/types/regex'
15
+ require 'kdl/types/base64'
16
+ require 'kdl/types/decimal'
17
+ require 'kdl/types/hostname'
18
+ require 'kdl/types/email'
19
+ require 'kdl/types/irl'
20
+ require 'kdl/types/url_template'
21
+
22
+ KDL::Types::MAPPING.freeze
data/lib/kdl/value.rb CHANGED
@@ -1,15 +1,39 @@
1
1
  module KDL
2
2
  class Value
3
- attr_reader :value
3
+ attr_reader :value, :format, :type
4
4
 
5
- def initialize(value)
5
+ def initialize(value, format: nil, type: nil)
6
6
  @value = value
7
+ @format = format
8
+ @type = type
9
+ end
10
+
11
+ def as_type(type, parser = nil)
12
+ if parser.nil?
13
+ self.class.new(value, format: format, type: type)
14
+ else
15
+ result = parser.call(self, type)
16
+ return self.as_type(type) if result.nil?
17
+
18
+ unless result.is_a?(::KDL::Value)
19
+ raise ArgumentError, "expected parser to return an instance of ::KDL::Value, got `#{result.class}'"
20
+ end
21
+
22
+ result
23
+ end
7
24
  end
8
25
 
9
26
  def to_s
27
+ return stringify_value unless type
28
+
29
+ "(#{StringDumper.stringify_identifier type})#{stringify_value}"
30
+ end
31
+
32
+ def stringify_value
33
+ return format % value if format
34
+
10
35
  value.to_s
11
36
  end
12
- alias inspect to_s
13
37
 
14
38
  class Int < Value
15
39
  def ==(other)
@@ -21,6 +45,16 @@ module KDL
21
45
  def ==(other)
22
46
  other.is_a?(Float) && value == other.value
23
47
  end
48
+
49
+ def stringify_value
50
+ return super.upcase unless value.is_a?(BigDecimal)
51
+
52
+ sign, digits, _, exponent = value.split
53
+ s = sign.negative? ? '-' : ''
54
+ s += "#{digits[0]}.#{digits[1..-1]}"
55
+ s += "E#{exponent.negative? ? '' : '+'}#{exponent - 1}"
56
+ s
57
+ end
24
58
  end
25
59
 
26
60
  class Boolean < Value
@@ -30,10 +64,9 @@ module KDL
30
64
  end
31
65
 
32
66
  class String < Value
33
- def to_s
34
- value.inspect
67
+ def stringify_value
68
+ StringDumper.call(value)
35
69
  end
36
- alias inspect to_s
37
70
 
38
71
  def ==(other)
39
72
  other.is_a?(String) && value == other.value
@@ -41,14 +74,13 @@ module KDL
41
74
  end
42
75
 
43
76
  class NullImpl < Value
44
- def initialize
45
- super(nil)
77
+ def initialize(_=nil, format: nil, type: nil)
78
+ super(nil, type: type)
46
79
  end
47
80
 
48
- def to_s
81
+ def stringify_value
49
82
  "null"
50
83
  end
51
- alias inspect to_s
52
84
 
53
85
  def ==(other)
54
86
  other.is_a?(NullImpl)
data/lib/kdl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KDL
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/kdl.rb CHANGED
@@ -3,10 +3,12 @@ require "kdl/tokenizer"
3
3
  require "kdl/document"
4
4
  require "kdl/value"
5
5
  require "kdl/node"
6
+ require "kdl/string_dumper"
7
+ require "kdl/types"
6
8
  require "kdl/kdl.tab"
7
9
 
8
10
  module KDL
9
- def self.parse_document(input)
10
- Parser.new.parse(input)
11
+ def self.parse_document(input, options = {})
12
+ Parser.new.parse(input, options)
11
13
  end
12
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Smith
7
+ - Danielle Smith
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-27 00:00:00.000000000 Z
11
+ date: 2021-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: racc
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simpleidn
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.1
27
41
  description: Ruby implementation of the KDL Document Language Spec
28
42
  email:
29
43
  - danini@hey.com
@@ -33,13 +47,15 @@ extra_rdoc_files: []
33
47
  files:
34
48
  - ".github/workflows/ruby.yml"
35
49
  - ".gitignore"
36
- - ".travis.yml"
50
+ - ".gitmodules"
37
51
  - CODE_OF_CONDUCT.md
38
52
  - Gemfile
39
53
  - LICENSE.txt
40
54
  - README.md
41
55
  - Rakefile
42
56
  - bin/console
57
+ - bin/racc
58
+ - bin/rake
43
59
  - bin/setup
44
60
  - kdl.gemspec
45
61
  - lib/kdl.rb
@@ -47,7 +63,30 @@ files:
47
63
  - lib/kdl/kdl.tab.rb
48
64
  - lib/kdl/kdl.yy
49
65
  - lib/kdl/node.rb
66
+ - lib/kdl/string_dumper.rb
50
67
  - lib/kdl/tokenizer.rb
68
+ - lib/kdl/types.rb
69
+ - lib/kdl/types/base64.rb
70
+ - lib/kdl/types/country.rb
71
+ - lib/kdl/types/country/iso3166_countries.rb
72
+ - lib/kdl/types/country/iso3166_subdivisions.rb
73
+ - lib/kdl/types/currency.rb
74
+ - lib/kdl/types/currency/iso4217_currencies.rb
75
+ - lib/kdl/types/date_time.rb
76
+ - lib/kdl/types/decimal.rb
77
+ - lib/kdl/types/duration.rb
78
+ - lib/kdl/types/duration/iso8601_parser.rb
79
+ - lib/kdl/types/email.rb
80
+ - lib/kdl/types/email/parser.rb
81
+ - lib/kdl/types/hostname.rb
82
+ - lib/kdl/types/hostname/validator.rb
83
+ - lib/kdl/types/ip.rb
84
+ - lib/kdl/types/irl.rb
85
+ - lib/kdl/types/irl/parser.rb
86
+ - lib/kdl/types/regex.rb
87
+ - lib/kdl/types/url.rb
88
+ - lib/kdl/types/url_template.rb
89
+ - lib/kdl/types/uuid.rb
51
90
  - lib/kdl/value.rb
52
91
  - lib/kdl/version.rb
53
92
  homepage: https://kdl.dev
@@ -55,8 +94,8 @@ licenses:
55
94
  - MIT
56
95
  metadata:
57
96
  homepage_uri: https://kdl.dev
58
- source_code_uri: https://github.com/jellymann/kdl-rb
59
- changelog_uri: https://github.com/jellymann/kdl-rb/releases
97
+ source_code_uri: https://github.com/danini-the-panini/kdl-rb
98
+ changelog_uri: https://github.com/danini-the-panini/kdl-rb/releases
60
99
  post_install_message:
61
100
  rdoc_options: []
62
101
  require_paths:
@@ -65,14 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
104
  requirements:
66
105
  - - ">="
67
106
  - !ruby/object:Gem::Version
68
- version: 2.3.0
107
+ version: 2.4.0
69
108
  required_rubygems_version: !ruby/object:Gem::Requirement
70
109
  requirements:
71
110
  - - ">="
72
111
  - !ruby/object:Gem::Version
73
112
  version: '0'
74
113
  requirements: []
75
- rubygems_version: 3.1.4
114
+ rubygems_version: 3.2.22
76
115
  signing_key:
77
116
  specification_version: 4
78
117
  summary: KDL Document Language
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.0
6
- before_install: gem install bundler -v 2.1.2