str2duck 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13d262e737dd246b94d5ba61744a2f436fd8b957
4
- data.tar.gz: 7353ed1e2ed73ce3d2b4c2052e948acc6f6d2a21
3
+ metadata.gz: c7da6d90a40042f4fbf8eb7ee19e1511bc87d0a8
4
+ data.tar.gz: 79aaa4ba8fc30ccb12939360379c8cd2e0c7efe8
5
5
  SHA512:
6
- metadata.gz: 56a9d31455f28a6b38a142e0352f8c1287c5701c250185bc308cd09c91dbab9d0e8b8fa07b52645d11c100ab7d95962e5d2388f7c22c5580786fc46a0a9e0f24
7
- data.tar.gz: c761bf9f825ce94193132f1acd2e4ee55c87f2d20dd4adcafc0481926211d3eac8a3d1bda47ba77450c3b44f253722c80d4222491d6c7e00e1c2e43d980cd52d
6
+ metadata.gz: 817f2c7e68c6b003505eb9ee45213ff9f76ca6f7e3c2e0f7fea604006901831e4d4662fd2b9150480789f0667e967578e768200a177f207f7480a73128e51794
7
+ data.tar.gz: 0064c0937546a4300b83973f253ea6c1394f3c08cf4cdffa1e5135aecad7a59b4b2fc61ee0ff29395b7af5dc8f87b45f44061d57c324fd96c264f5747d458e21
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.4.0
data/examples/sample.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative "../lib/str2duck"
1
+ require "str2duck"
2
2
 
3
3
  [
4
4
  "2011-03-12",
@@ -27,7 +27,7 @@ begin
27
27
 
28
28
  [
29
29
  "2011-03-12",
30
- "2007-07-20 18:59:27 +0200",
30
+ "2007-07-20 18:59:27 +0100",
31
31
  "2010-10-30 18:02:56 +0200",
32
32
  "2012-09-12T14:49:50+02:00",
33
33
  "123",
data/examples/test.rb CHANGED
@@ -1,11 +1,13 @@
1
- require_relative "../lib/str2duck"
1
+ require "str2duck"
2
2
 
3
- puts 123.duck.class
4
- puts ["hello","world"].duck.class
5
- puts '{"hello":"world"}'.duck.class
6
- puts "hello: world".duck.class,"","---"
3
+ puts "false".to_duck.class
7
4
 
8
-
9
- Str2Duck::Config.yaml = false
10
- puts Str2Duck::Config.list,"","---"
11
- puts "hello: world".duck.class
5
+ # puts 123.duck.class
6
+ # puts ["hello","world"].duck.class
7
+ # puts '{"hello":"world"}'.duck.class
8
+ # puts "hello: world".duck.class,"","---"
9
+ #
10
+ #
11
+ # Str2Duck::Config.yaml = false
12
+ # puts Str2Duck::Config.list,"","---"
13
+ # puts "hello: world".duck.class
@@ -8,7 +8,12 @@ module Str2Duck
8
8
  if defined? DateTime
9
9
  return DateTime.parse obj
10
10
  else
11
+
11
12
  time_parts= obj.scan(/\d+/).map(&:to_i)
13
+
14
+ puts time_parts.inspect
15
+ Process.exit
16
+
12
17
  if time_parts.count == 8
13
18
  2.times{time_parts.pop}
14
19
  elsif time_parts.count == 6
@@ -4,15 +4,17 @@ module Str2Duck
4
4
 
5
5
  module Object
6
6
 
7
- def duck(self_obj= self)
7
+ def to_duck(self_obj= self)
8
+
8
9
  if self_obj.class <= String
9
10
  Str2Duck::MPatch::String.duck(self_obj)
10
11
  else
11
12
  return self_obj
12
13
  end
14
+
13
15
  end
14
16
 
15
- alias :to_duck :duck
17
+ alias :duck :to_duck
16
18
 
17
19
  self.instance_methods.each do |symbol|
18
20
  module_function symbol
@@ -4,10 +4,10 @@ module Str2Duck
4
4
 
5
5
  module String
6
6
 
7
- def duck(self_obj= self)
7
+ def to_duck(self_obj= self)
8
8
  Str2Duck.parse(self_obj)
9
9
  end
10
- alias :to_duck :duck
10
+ alias :duck :to_duck
11
11
 
12
12
  self.instance_methods.each do |symbol|
13
13
  module_function symbol
@@ -1,18 +1,19 @@
1
1
  #encoding: UTF-8
2
2
  module Str2Duck
3
3
 
4
- def self.parse string_data_obj
5
- raise ArgumentError,"invalid input, must be string!" if string_data_obj.class != String
6
- return_value= nil
4
+ def self.parse str
5
+ raise(ArgumentError,"invalid input, must be string like") unless str.class <= String
7
6
 
7
+ var= nil
8
8
  [ :datetime, :date, :time, :true, :false, :float, :integer, :json, :yaml ].each do |method_name|
9
9
  if ::Str2Duck::Config.__send__(method_name)
10
- return_value ||= Str2Duck::Format.__send__ method_name, string_data_obj
10
+ var= Str2Duck::Format.__send__ method_name, str
11
+ return var unless var.nil?
11
12
  end
12
13
  end
13
14
 
14
- return_value ||= string_data_obj
15
- return return_value
15
+ return str
16
+
16
17
  end
17
18
 
18
19
  end
@@ -2,9 +2,6 @@
2
2
  module Str2Duck
3
3
  module Regexp
4
4
 
5
- require 'json'
6
- require 'yaml'
7
-
8
5
  @@year = '\d+'
9
6
  class << self
10
7
 
data/lib/str2duck.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  #encoding: UTF-8
2
2
 
3
- require File.join File.dirname(__FILE__),'str2duck','support'
3
+ require 'json'
4
+ require 'yaml'
4
5
 
5
- require File.join File.dirname(__FILE__),'str2duck','regexp'
6
- require File.join File.dirname(__FILE__),'str2duck','format'
7
- require File.join File.dirname(__FILE__),'str2duck','config'
6
+ require 'str2duck/support'
8
7
 
9
- require File.join File.dirname(__FILE__),'str2duck','parser'
8
+ require 'str2duck/regexp'
9
+ require 'str2duck/format'
10
+ require 'str2duck/config'
10
11
 
11
- require File.join File.dirname(__FILE__),'str2duck','mpatch','string'
12
- require File.join File.dirname(__FILE__),'str2duck','mpatch','object'
12
+ require 'str2duck/parser'
13
+
14
+ require 'str2duck/mpatch/string'
15
+ require 'str2duck/mpatch/object'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: str2duck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-02 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " Parse string into obj "
14
14
  email:
@@ -23,7 +23,6 @@ files:
23
23
  - README.md
24
24
  - Rakefile
25
25
  - VERSION
26
- - dump/find_regexp.rb
27
26
  - examples/sample.rb
28
27
  - examples/test.rb
29
28
  - files.rb
data/dump/find_regexp.rb DELETED
@@ -1,19 +0,0 @@
1
- #begin
2
- # string_input= string_data_obj
3
- # contain= nil
4
- # ["[", "]","^","$","*","/"].each do |one_sym|
5
- # if string_input.include? one_sym
6
- # contain ||= true
7
- # end
8
- # end
9
- # if contain == true
10
- # string_regexp= Regexp.new(string_input).inspect#.gsub('\\','')
11
- # string_regexp= string_regexp[1..(string_regexp.length-2)]
12
- # if string_input == string_regexp
13
- # return Regexp.new(string_input)
14
- # else
15
- # raise ArgumentError,"invalid input string"
16
- # end
17
- # end
18
- #rescue ArgumentError
19
- #end