str2duck 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +6 -1
- data/VERSION +1 -1
- data/examples/sample.rb +3 -1
- data/examples/test.rb +36 -0
- data/lib/str2duck/format.rb +15 -0
- data/lib/str2duck/parser.rb +1 -1
- data/lib/str2duck/regexp.rb +23 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjBlZjU1NjdmZDdiMjAyZDBkMGJlNzQyMWZjZGMxOTZiNmZlYjUzOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzI5OWJhODk0MTUwNWY5YmEzODhkMzJkYmRiYWQ3ZTExZGJiMzA3MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjNiMDdlN2JiZTExMGUxZGJiN2RjMWIxMzZlNjc1NjkxOWE3ZjVhNTUyYTIz
|
10
|
+
NGU4Mjg0OWY3OWE5MjViZmIwYWY5MzY3MTY0MGYwZTAwOTgyYTk0Y2M0ZDhk
|
11
|
+
ZTYxZmFlYTA5MTY3MTgwYjhjMDNiNzVjOTljNDU4MDFkZTIzYmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTE3YThjOTFhNWM2YTlhMTY2MWViZWVmZTRkNjU4NTc4NWMxMzkzYmYwNjBl
|
14
|
+
NjE5ZjE4MmM2MTdlOGQ3MjdjODBmNmI0MGFhMTg5YTIzMTBjM2U1M2JlNTcx
|
15
|
+
MjA5MmEwNzgzMjFhNDUxN2Y0YzMzOWVjZjVmZmEyM2I0NTU1NTk=
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
data/examples/sample.rb
CHANGED
data/examples/test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "../lib/str2duck"
|
2
|
+
|
3
|
+
require 'debugger'
|
4
|
+
debugger
|
5
|
+
[
|
6
|
+
"false"
|
7
|
+
].each do |object|
|
8
|
+
puts object.duck,object.duck.class,""
|
9
|
+
end
|
10
|
+
|
11
|
+
#begin
|
12
|
+
#
|
13
|
+
# require File.join 'active_support','time'
|
14
|
+
#
|
15
|
+
# puts "but if you load the Active support gem like when you do anyway in Rails, the duck will be more with time formats flexible"
|
16
|
+
#
|
17
|
+
# [
|
18
|
+
# "2011-03-12",
|
19
|
+
# "2007-07-20 18:59:27 +0200",
|
20
|
+
# "2010-10-30 18:02:56 +0200",
|
21
|
+
# "2012-09-12T14:49:50+02:00",
|
22
|
+
# "123",
|
23
|
+
# "asd",
|
24
|
+
# "123.432",
|
25
|
+
# "true",
|
26
|
+
# "false",
|
27
|
+
# "some string data"
|
28
|
+
# ].each do |object|
|
29
|
+
# puts object.duck,object.duck.class,""
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# puts "Sun, 28 Aug 2005".duck.class
|
33
|
+
# puts "Fri, 25 Jan 2013 20:02:15 +0100".duck.class
|
34
|
+
#
|
35
|
+
#rescue LoadError
|
36
|
+
#end
|
data/lib/str2duck/format.rb
CHANGED
@@ -73,6 +73,21 @@ module Str2Duck
|
|
73
73
|
nil
|
74
74
|
end
|
75
75
|
|
76
|
+
def json obj
|
77
|
+
if Str2Duck::Regexp.json?(obj)
|
78
|
+
return JSON.parse(obj)
|
79
|
+
end
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
|
83
|
+
# damn, this thing eats almost everything...
|
84
|
+
def yaml obj
|
85
|
+
if Str2Duck::Regexp.yaml?(obj)
|
86
|
+
return YAML.load(obj)
|
87
|
+
end
|
88
|
+
nil
|
89
|
+
end
|
90
|
+
|
76
91
|
end
|
77
92
|
end
|
78
93
|
end
|
data/lib/str2duck/parser.rb
CHANGED
@@ -5,7 +5,7 @@ module Str2Duck
|
|
5
5
|
raise ArgumentError,"invalid input, must be string!" if string_data_obj.class != String
|
6
6
|
return_value= nil
|
7
7
|
|
8
|
-
|
8
|
+
[ :datetime, :date, :time, :true, :false, :float, :integer, :json, :yaml ].each do |method_name|
|
9
9
|
return_value ||= Str2Duck::Format.__send__ method_name, string_data_obj
|
10
10
|
end
|
11
11
|
|
data/lib/str2duck/regexp.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
#encoding: UTF-8
|
2
2
|
module Str2Duck
|
3
3
|
module Regexp
|
4
|
+
|
5
|
+
require 'json'
|
6
|
+
require 'yaml'
|
7
|
+
|
4
8
|
@@year = '\d+'
|
5
9
|
class << self
|
6
10
|
|
@@ -50,7 +54,7 @@ module Str2Duck
|
|
50
54
|
end
|
51
55
|
|
52
56
|
def false? obj
|
53
|
-
return Str2Duck.return_value_parse obj =~ /^
|
57
|
+
return Str2Duck.return_value_parse obj =~ /^false$/
|
54
58
|
end
|
55
59
|
|
56
60
|
def float? obj
|
@@ -61,6 +65,24 @@ module Str2Duck
|
|
61
65
|
return Str2Duck.return_value_parse obj =~ /^\d+$/
|
62
66
|
end
|
63
67
|
|
68
|
+
def json? obj
|
69
|
+
begin
|
70
|
+
JSON.parse(obj)
|
71
|
+
return true
|
72
|
+
rescue ::JSON::ParserError
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def yaml? obj
|
78
|
+
begin
|
79
|
+
YAML.load(obj)
|
80
|
+
return true
|
81
|
+
rescue ::Psych::SyntaxError,::ArgumentError
|
82
|
+
return false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
64
86
|
end
|
65
87
|
end
|
66
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: str2duck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- VERSION
|
26
26
|
- dump/find_regexp.rb
|
27
27
|
- examples/sample.rb
|
28
|
+
- examples/test.rb
|
28
29
|
- files.rb
|
29
30
|
- lib/str2duck.rb
|
30
31
|
- lib/str2duck/format.rb
|