crack 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ rdoc
5
5
  pkg
6
6
  *.gem
7
7
  /.bundle
8
+ /Gemfile.lock
@@ -38,12 +38,12 @@ module Crack
38
38
  end
39
39
 
40
40
  # matches YAML-formatted dates
41
- DATE_REGEX = /^\d{4}-\d{2}-\d{2}$|^\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?$/
41
+ DATE_REGEX = /^\d{4}-\d{2}-\d{2}$|^\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)$/
42
42
 
43
43
  # Ensure that ":" and "," are always followed by a space
44
44
  def self.convert_json_to_yaml(json) #:nodoc:
45
45
  json = String.new(json) #can't modify a frozen string
46
- scanner, quoting, marks, pos, times = StringScanner.new(json), false, [], nil, []
46
+ scanner, quoting, marks, pos, date_starts, date_ends = StringScanner.new(json), false, [], nil, [], []
47
47
  while scanner.scan_until(/(\\['"]|['":,\/\\]|\\.)/)
48
48
  case char = scanner[1]
49
49
  when '"', "'"
@@ -56,7 +56,8 @@ module Crack
56
56
  # oh, and increment them for each current mark, each one is an extra padded space that bumps
57
57
  # the position in the final YAML output
58
58
  total_marks = marks.size
59
- times << pos+total_marks << scanner.pos+total_marks
59
+ date_starts << pos+total_marks
60
+ date_ends << scanner.pos+total_marks
60
61
  end
61
62
  quoting = false
62
63
  end
@@ -84,10 +85,18 @@ module Crack
84
85
  end
85
86
  output = output * " "
86
87
 
87
- times.each { |i| output[i-1] = ' ' }
88
+ format_dates(output, date_starts, date_ends)
88
89
  output.gsub!(/\\\//, '/')
89
90
  output
90
91
  end
91
92
  end
93
+
94
+ def self.format_dates(output, date_starts, date_ends)
95
+ if YAML.constants.include?('Syck')
96
+ (date_starts + date_ends).each { |i| output[i-1] = ' ' }
97
+ else
98
+ date_starts.each { |i| output[i-2] = '!!timestamp ' }
99
+ end
100
+ end
92
101
  end
93
102
  end
@@ -1,3 +1,3 @@
1
1
  module Crack
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: safe_yaml
@@ -36,7 +36,6 @@ extra_rdoc_files: []
36
36
  files:
37
37
  - .gitignore
38
38
  - Gemfile
39
- - Gemfile.lock
40
39
  - History
41
40
  - LICENSE
42
41
  - README.md
@@ -1,22 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- crack (0.3.2)
5
- safe_yaml (~> 0.9.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- jnunemaker-matchy (0.4.0)
11
- minitest (5.0.3)
12
- rake (10.0.3)
13
- safe_yaml (0.9.2)
14
-
15
- PLATFORMS
16
- ruby
17
-
18
- DEPENDENCIES
19
- crack!
20
- jnunemaker-matchy
21
- minitest
22
- rake