shale 0.7.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,6 +47,17 @@ module Shale
47
47
  value&.iso8601
48
48
  end
49
49
 
50
+ # Use ISO 8601 format in CSV document
51
+ #
52
+ # @param [Date] value
53
+ #
54
+ # @return [String]
55
+ #
56
+ # @api private
57
+ def self.as_csv(value, **)
58
+ value&.iso8601
59
+ end
60
+
50
61
  # Use ISO 8601 format in XML document
51
62
  #
52
63
  # @param [Date] value Value to convert to XML
@@ -47,6 +47,17 @@ module Shale
47
47
  value&.iso8601
48
48
  end
49
49
 
50
+ # Use ISO 8601 format in CSV document
51
+ #
52
+ # @param [Time] value
53
+ #
54
+ # @return [String]
55
+ #
56
+ # @api private
57
+ def self.as_csv(value, **)
58
+ value&.iso8601
59
+ end
60
+
50
61
  # Use ISO 8601 format in XML document
51
62
  #
52
63
  # @param [Time] value Value to convert to XML
@@ -111,6 +111,28 @@ module Shale
111
111
  value
112
112
  end
113
113
 
114
+ # Extract value from CSV document
115
+ #
116
+ # @param [any] value
117
+ #
118
+ # @return [any]
119
+ #
120
+ # @api private
121
+ def of_csv(value, **)
122
+ value
123
+ end
124
+
125
+ # Convert value to form accepted by CSV document
126
+ #
127
+ # @param [any] value
128
+ #
129
+ # @return [any]
130
+ #
131
+ # @api private
132
+ def as_csv(value, **)
133
+ value
134
+ end
135
+
114
136
  # Extract value from XML document
115
137
  #
116
138
  # @param [Shale::Adapter::<XML adapter>::Node] value
data/lib/shale/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Shale
4
4
  # @api private
5
- VERSION = '0.7.1'
5
+ VERSION = '0.9.0'
6
6
  end
data/lib/shale.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'yaml'
4
4
 
5
5
  require_relative 'shale/mapper'
6
+ require_relative 'shale/adapter/csv'
6
7
  require_relative 'shale/adapter/json'
7
8
  require_relative 'shale/type/boolean'
8
9
  require_relative 'shale/type/date'
@@ -15,7 +16,7 @@ require_relative 'shale/version'
15
16
  # Main library namespace
16
17
  #
17
18
  # Shale uses adapters for parsing and serializing documents.
18
- # For handling JSON and YAML, adapter must implement .load and .dump methods, so
19
+ # For handling JSON, YAML, TOML and CSV, adapter must implement .load and .dump methods, so
19
20
  # e.g for handling JSON, MultiJson works out of the box.
20
21
  #
21
22
  # Adapters for XML handling are more complicated and must conform to [@see shale/adapter/rexml]
@@ -29,9 +30,11 @@ require_relative 'shale/version'
29
30
  # Shale.json_adapter = MultiJson
30
31
  # Shale.json_adapter # => MultiJson
31
32
  #
32
- # @example setting YAML adapter for handling YAML documents
33
- # Shale.yaml_adapter = MultiJson
34
- # Shale.yaml_adapter # => MultiJson
33
+ # @example setting TOML adapter for handling TOML documents
34
+ # require 'shale/adapter/toml_rb'
35
+ #
36
+ # Shale.toml_adapter = Shale::Adapter::TomlRB
37
+ # Shale.toml_adapter # => Shale::Adapter::TomlRB
35
38
  #
36
39
  # @example setting REXML adapter for handling XML documents
37
40
  # Shale.xml_adapter = Shale::Adapter::REXML
@@ -86,6 +89,16 @@ module Shale
86
89
  # @api public
87
90
  attr_accessor :toml_adapter
88
91
 
92
+ # Set CSV adapter
93
+ #
94
+ # @param [.load, .dump] adapter
95
+ #
96
+ # @example
97
+ # Shale.csv_adapter = Shale::Adapter::CSV
98
+ #
99
+ # @api public
100
+ attr_writer :csv_adapter
101
+
89
102
  # XML adapter accessor. Available adapters are Shale::Adapter::REXML,
90
103
  # Shale::Adapter::Nokogiri and Shale::Adapter::Ox
91
104
  #
@@ -126,5 +139,18 @@ module Shale
126
139
  def yaml_adapter
127
140
  @yaml_adapter || YAML
128
141
  end
142
+
143
+ # Return CSV adapter. By default CSV is used
144
+ #
145
+ # @return [.load, .dump]
146
+ #
147
+ # @example
148
+ # Shale.csv_adapter
149
+ # # => Shale::Adapter::CSV
150
+ #
151
+ # @api public
152
+ def csv_adapter
153
+ @csv_adapter || Adapter::CSV
154
+ end
129
155
  end
130
156
  end
data/shale.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Kamil Giszczak']
9
9
  spec.email = ['beerkg@gmail.com']
10
10
 
11
- spec.summary = 'Ruby object mapper and serializer for XML, JSON, TOML and YAML.'
12
- spec.description = 'Ruby object mapper and serializer for XML, JSON, TOML and YAML.'
11
+ spec.summary = 'Ruby object mapper and serializer for XML, JSON, TOML, CSV and YAML.'
12
+ spec.description = 'Ruby object mapper and serializer for XML, JSON, TOML, CSV and YAML.'
13
13
  spec.homepage = 'https://shalerb.org'
14
14
  spec.license = 'MIT'
15
15
 
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.bindir = 'exe'
27
27
  spec.executables = 'shaleb'
28
28
 
29
- spec.required_ruby_version = '>= 2.7.0'
29
+ spec.required_ruby_version = '>= 2.6.0'
30
30
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kamil Giszczak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-12 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Ruby object mapper and serializer for XML, JSON, TOML and YAML.
13
+ description: Ruby object mapper and serializer for XML, JSON, TOML, CSV and YAML.
14
14
  email:
15
15
  - beerkg@gmail.com
16
16
  executables:
@@ -23,6 +23,7 @@ files:
23
23
  - README.md
24
24
  - exe/shaleb
25
25
  - lib/shale.rb
26
+ - lib/shale/adapter/csv.rb
26
27
  - lib/shale/adapter/json.rb
27
28
  - lib/shale/adapter/nokogiri.rb
28
29
  - lib/shale/adapter/nokogiri/document.rb
@@ -41,8 +42,16 @@ files:
41
42
  - lib/shale/mapping/descriptor/xml.rb
42
43
  - lib/shale/mapping/descriptor/xml_namespace.rb
43
44
  - lib/shale/mapping/dict.rb
45
+ - lib/shale/mapping/dict_base.rb
46
+ - lib/shale/mapping/dict_group.rb
47
+ - lib/shale/mapping/group/dict.rb
48
+ - lib/shale/mapping/group/dict_grouping.rb
49
+ - lib/shale/mapping/group/xml.rb
50
+ - lib/shale/mapping/group/xml_grouping.rb
44
51
  - lib/shale/mapping/validator.rb
45
52
  - lib/shale/mapping/xml.rb
53
+ - lib/shale/mapping/xml_base.rb
54
+ - lib/shale/mapping/xml_group.rb
46
55
  - lib/shale/schema.rb
47
56
  - lib/shale/schema/compiler/boolean.rb
48
57
  - lib/shale/schema/compiler/complex.rb
@@ -108,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
117
  requirements:
109
118
  - - ">="
110
119
  - !ruby/object:Gem::Version
111
- version: 2.7.0
120
+ version: 2.6.0
112
121
  required_rubygems_version: !ruby/object:Gem::Requirement
113
122
  requirements:
114
123
  - - ">="
@@ -118,5 +127,5 @@ requirements: []
118
127
  rubygems_version: 3.3.7
119
128
  signing_key:
120
129
  specification_version: 4
121
- summary: Ruby object mapper and serializer for XML, JSON, TOML and YAML.
130
+ summary: Ruby object mapper and serializer for XML, JSON, TOML, CSV and YAML.
122
131
  test_files: []