str2duck 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/examples/sample.rb +2 -2
- data/examples/test.rb +11 -9
- data/lib/str2duck/format.rb +5 -0
- data/lib/str2duck/mpatch/object.rb +4 -2
- data/lib/str2duck/mpatch/string.rb +2 -2
- data/lib/str2duck/parser.rb +7 -6
- data/lib/str2duck/regexp.rb +0 -3
- data/lib/str2duck.rb +10 -7
- metadata +2 -3
- data/dump/find_regexp.rb +0 -19
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c7da6d90a40042f4fbf8eb7ee19e1511bc87d0a8
         | 
| 4 | 
            +
              data.tar.gz: 79aaa4ba8fc30ccb12939360379c8cd2e0c7efe8
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 817f2c7e68c6b003505eb9ee45213ff9f76ca6f7e3c2e0f7fea604006901831e4d4662fd2b9150480789f0667e967578e768200a177f207f7480a73128e51794
         | 
| 7 | 
            +
              data.tar.gz: 0064c0937546a4300b83973f253ea6c1394f3c08cf4cdffa1e5135aecad7a59b4b2fc61ee0ff29395b7af5dc8f87b45f44061d57c324fd96c264f5747d458e21
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            1. | 
| 1 | 
            +
            1.4.0
         | 
    
        data/examples/sample.rb
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
             | 
| 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 + | 
| 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 | 
            -
             | 
| 1 | 
            +
            require "str2duck"
         | 
| 2 2 |  | 
| 3 | 
            -
            puts  | 
| 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 | 
            -
             | 
| 10 | 
            -
            puts  | 
| 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
         | 
    
        data/lib/str2duck/format.rb
    CHANGED
    
    | @@ -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  | 
| 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 : | 
| 17 | 
            +
                  alias :duck :to_duck
         | 
| 16 18 |  | 
| 17 19 | 
             
                  self.instance_methods.each do |symbol|
         | 
| 18 20 | 
             
                    module_function symbol
         | 
    
        data/lib/str2duck/parser.rb
    CHANGED
    
    | @@ -1,18 +1,19 @@ | |
| 1 1 | 
             
            #encoding: UTF-8
         | 
| 2 2 | 
             
            module Str2Duck
         | 
| 3 3 |  | 
| 4 | 
            -
              def self.parse  | 
| 5 | 
            -
                raise | 
| 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 | 
            -
                     | 
| 10 | 
            +
                    var= Str2Duck::Format.__send__ method_name, str
         | 
| 11 | 
            +
                    return var unless var.nil?
         | 
| 11 12 | 
             
                  end
         | 
| 12 13 | 
             
                end
         | 
| 13 14 |  | 
| 14 | 
            -
                 | 
| 15 | 
            -
             | 
| 15 | 
            +
                return str
         | 
| 16 | 
            +
             | 
| 16 17 | 
             
              end
         | 
| 17 18 |  | 
| 18 19 | 
             
            end
         | 
    
        data/lib/str2duck/regexp.rb
    CHANGED
    
    
    
        data/lib/str2duck.rb
    CHANGED
    
    | @@ -1,12 +1,15 @@ | |
| 1 1 | 
             
            #encoding: UTF-8
         | 
| 2 2 |  | 
| 3 | 
            -
            require  | 
| 3 | 
            +
            require 'json'
         | 
| 4 | 
            +
            require 'yaml'
         | 
| 4 5 |  | 
| 5 | 
            -
            require  | 
| 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  | 
| 8 | 
            +
            require 'str2duck/regexp'
         | 
| 9 | 
            +
            require 'str2duck/format'
         | 
| 10 | 
            +
            require 'str2duck/config'
         | 
| 10 11 |  | 
| 11 | 
            -
            require  | 
| 12 | 
            -
             | 
| 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. | 
| 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- | 
| 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
         |