lotus-utils 0.3.2 → 0.3.3
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/CHANGELOG.md +5 -0
- data/lib/lotus/utils/hash.rb +9 -5
- data/lib/lotus/utils/kernel.rb +27 -3
- data/lib/lotus/utils/string.rb +15 -7
- data/lib/lotus/utils/version.rb +4 -1
- data/lotus-utils.gemspec +2 -2
- metadata +5 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 629a22895276c357e5ee478c10eb6fd0c2c4ef4a
         | 
| 4 | 
            +
              data.tar.gz: 185f59a1c22e690428f1675aa0ebb2a1553ad4ad
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a3e7907833d632771a62ccd573d72238ca7f454f28c84f440eb85b6cf6b49bb635214bc22d05431861ff163246ef82fea184c30b52132c54c8323e7d4eac157c
         | 
| 7 | 
            +
              data.tar.gz: 589fd11dc42724192687b86d4848b378d90c7a14516fb69117667a7b021df56facd67f91ebbba7fb53fe492a2e010ee22bf6622910fa0a6bed61f83fb19befb7
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,6 +1,11 @@ | |
| 1 1 | 
             
            # Lotus::Utils
         | 
| 2 2 | 
             
            Ruby core extentions and class utilities for Lotus
         | 
| 3 3 |  | 
| 4 | 
            +
            ## v0.3.3 - 2015-01-08
         | 
| 5 | 
            +
            ### Fixed
         | 
| 6 | 
            +
            - [Luca Guidi] Ensure to return the right offending object if a missing method is called with Utils::String and Hash (eg. `Utils::Hash.new(a: 1).all? {|_, v| v.foo }` blame `v` instead of `Hash`)
         | 
| 7 | 
            +
            - [Luca Guidi] Raise an error if try to coerce non numeric strings into Integer, Float & BigDecimal (eg. `Utils::Kernel.Integer("hello") # => raise TypeError`)
         | 
| 8 | 
            +
             | 
| 4 9 | 
             
            ## v0.3.2 - 2014-12-23
         | 
| 5 10 | 
             
            ### Added
         | 
| 6 11 | 
             
            - [Luca Guidi] Official support for Ruby 2.2
         | 
    
        data/lib/lotus/utils/hash.rb
    CHANGED
    
    | @@ -259,12 +259,16 @@ module Lotus | |
| 259 259 | 
             
                  #
         | 
| 260 260 | 
             
                  # @api private
         | 
| 261 261 | 
             
                  # @since 0.3.0
         | 
| 262 | 
            +
                  #
         | 
| 263 | 
            +
                  # @raise [NoMethodError] If doesn't respond to the given method
         | 
| 262 264 | 
             
                  def method_missing(m, *args, &blk)
         | 
| 263 | 
            -
                     | 
| 264 | 
            -
             | 
| 265 | 
            -
             | 
| 266 | 
            -
             | 
| 267 | 
            -
                     | 
| 265 | 
            +
                    if respond_to?(m)
         | 
| 266 | 
            +
                      h = @hash.__send__(m, *args, &blk)
         | 
| 267 | 
            +
                      h = self.class.new(h) if h.is_a?(::Hash)
         | 
| 268 | 
            +
                      h
         | 
| 269 | 
            +
                    else
         | 
| 270 | 
            +
                      raise NoMethodError.new(%(undefined method `#{ m }' for #{ @hash }:#{ self.class }))
         | 
| 271 | 
            +
                    end
         | 
| 268 272 | 
             
                  end
         | 
| 269 273 |  | 
| 270 274 | 
             
                  # Override Ruby's respond_to_missing? in order to support ::Hash interface
         | 
    
        data/lib/lotus/utils/kernel.rb
    CHANGED
    
    | @@ -17,6 +17,14 @@ module Lotus | |
| 17 17 | 
             
                # Kernel utilities
         | 
| 18 18 | 
             
                # @since 0.1.1
         | 
| 19 19 | 
             
                module Kernel
         | 
| 20 | 
            +
                  # Matcher for numeric values
         | 
| 21 | 
            +
                  #
         | 
| 22 | 
            +
                  # @since 0.3.3
         | 
| 23 | 
            +
                  # @api private
         | 
| 24 | 
            +
                  #
         | 
| 25 | 
            +
                  # @see Lotus::Utils::Kernel.Integer
         | 
| 26 | 
            +
                  NUMERIC_MATCHER = /\A([\d\/\.\+iE]+|NaN|Infinity)\z/.freeze
         | 
| 27 | 
            +
             | 
| 20 28 | 
             
                  # Coerces the argument to be an Array.
         | 
| 21 29 | 
             
                  #
         | 
| 22 30 | 
             
                  # It's similar to Ruby's Kernel.Array, but it applies further
         | 
| @@ -285,6 +293,10 @@ module Lotus | |
| 285 293 | 
             
                  #   input = OpenStruct.new(color: 'purple')
         | 
| 286 294 | 
             
                  #   Lotus::Utils::Kernel.Integer(input) # => TypeError
         | 
| 287 295 | 
             
                  #
         | 
| 296 | 
            +
                  #   # String that doesn't represent an integer
         | 
| 297 | 
            +
                  #   input = 'hello'
         | 
| 298 | 
            +
                  #   Lotus::Utils::Kernel.Integer(input) # => TypeError
         | 
| 299 | 
            +
                  #
         | 
| 288 300 | 
             
                  #   # When true
         | 
| 289 301 | 
             
                  #   input = true
         | 
| 290 302 | 
             
                  #   Lotus::Utils::Kernel.Integer(input) # => TypeError
         | 
| @@ -320,7 +332,8 @@ module Lotus | |
| 320 332 | 
             
                    super(arg)
         | 
| 321 333 | 
             
                  rescue ArgumentError, TypeError, NoMethodError
         | 
| 322 334 | 
             
                    begin
         | 
| 323 | 
            -
                       | 
| 335 | 
            +
                      case arg
         | 
| 336 | 
            +
                      when NilClass, ->(a) { a.respond_to?(:to_i) && a.to_s.match(NUMERIC_MATCHER) }
         | 
| 324 337 | 
             
                        arg.to_i
         | 
| 325 338 | 
             
                      else
         | 
| 326 339 | 
             
                        raise TypeError.new "can't convert into Integer"
         | 
| @@ -398,6 +411,10 @@ module Lotus | |
| 398 411 | 
             
                  #   input = Time.now
         | 
| 399 412 | 
             
                  #   Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
         | 
| 400 413 | 
             
                  #
         | 
| 414 | 
            +
                  #   # String that doesn't represent a big decimal
         | 
| 415 | 
            +
                  #   input = 'hello'
         | 
| 416 | 
            +
                  #   Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
         | 
| 417 | 
            +
                  #
         | 
| 401 418 | 
             
                  #   # Missing #respond_to?
         | 
| 402 419 | 
             
                  #   input = BasicObject.new
         | 
| 403 420 | 
             
                  #   Lotus::Utils::Kernel.BigDecimal(input) # => TypeError
         | 
| @@ -406,8 +423,10 @@ module Lotus | |
| 406 423 | 
             
                    when ->(a) { a.respond_to?(:to_d) } then arg.to_d
         | 
| 407 424 | 
             
                    when Float, Complex, Rational
         | 
| 408 425 | 
             
                      BigDecimal(arg.to_s)
         | 
| 409 | 
            -
                     | 
| 426 | 
            +
                    when ->(a) { a.to_s.match(NUMERIC_MATCHER) }
         | 
| 410 427 | 
             
                      BigDecimal.new(arg)
         | 
| 428 | 
            +
                    else
         | 
| 429 | 
            +
                      raise TypeError.new "can't convert into BigDecimal"
         | 
| 411 430 | 
             
                    end
         | 
| 412 431 | 
             
                  rescue NoMethodError
         | 
| 413 432 | 
             
                    raise TypeError.new "can't convert into BigDecimal"
         | 
| @@ -514,6 +533,10 @@ module Lotus | |
| 514 533 | 
             
                  #   input = BasicObject.new
         | 
| 515 534 | 
             
                  #   Lotus::Utils::Kernel.Float(input) # => TypeError
         | 
| 516 535 | 
             
                  #
         | 
| 536 | 
            +
                  #   # String that doesn't represent a float
         | 
| 537 | 
            +
                  #   input = 'hello'
         | 
| 538 | 
            +
                  #   Lotus::Utils::Kernel.Float(input) # => TypeError
         | 
| 539 | 
            +
                  #
         | 
| 517 540 | 
             
                  #   # big rational
         | 
| 518 541 | 
             
                  #   input = Rational(-8) ** Rational(1, 3)
         | 
| 519 542 | 
             
                  #   Lotus::Utils::Kernel.Float(input) # => TypeError
         | 
| @@ -525,7 +548,8 @@ module Lotus | |
| 525 548 | 
             
                    super(arg)
         | 
| 526 549 | 
             
                  rescue ArgumentError, TypeError
         | 
| 527 550 | 
             
                    begin
         | 
| 528 | 
            -
                       | 
| 551 | 
            +
                      case arg
         | 
| 552 | 
            +
                      when NilClass, ->(a) { a.respond_to?(:to_f) && a.to_s.match(NUMERIC_MATCHER) }
         | 
| 529 553 | 
             
                        arg.to_f
         | 
| 530 554 | 
             
                      else
         | 
| 531 555 | 
             
                        raise TypeError.new "can't convert into Float"
         | 
    
        data/lib/lotus/utils/string.rb
    CHANGED
    
    | @@ -207,20 +207,28 @@ module Lotus | |
| 207 207 | 
             
                  # @see http://www.ruby-doc.org/core/String.html#method-i-gsub
         | 
| 208 208 | 
             
                  #
         | 
| 209 209 | 
             
                  # @since 0.3.0
         | 
| 210 | 
            -
                  def gsub(pattern, replacement, &blk)
         | 
| 211 | 
            -
                     | 
| 210 | 
            +
                  def gsub(pattern, replacement = nil, &blk)
         | 
| 211 | 
            +
                    if block_given?
         | 
| 212 | 
            +
                      @string.gsub(pattern, &blk)
         | 
| 213 | 
            +
                    else
         | 
| 214 | 
            +
                      @string.gsub(pattern, replacement)
         | 
| 215 | 
            +
                    end
         | 
| 212 216 | 
             
                  end
         | 
| 213 217 |  | 
| 214 218 | 
             
                  # Override Ruby's method_missing in order to provide ::String interface
         | 
| 215 219 | 
             
                  #
         | 
| 216 220 | 
             
                  # @api private
         | 
| 217 221 | 
             
                  # @since 0.3.0
         | 
| 222 | 
            +
                  #
         | 
| 223 | 
            +
                  # @raise [NoMethodError] If doesn't respond to the given method
         | 
| 218 224 | 
             
                  def method_missing(m, *args, &blk)
         | 
| 219 | 
            -
                     | 
| 220 | 
            -
             | 
| 221 | 
            -
             | 
| 222 | 
            -
             | 
| 223 | 
            -
                     | 
| 225 | 
            +
                    if respond_to?(m)
         | 
| 226 | 
            +
                      s = @string.__send__(m, *args, &blk)
         | 
| 227 | 
            +
                      s = self.class.new(s) if s.is_a?(::String)
         | 
| 228 | 
            +
                      s
         | 
| 229 | 
            +
                    else
         | 
| 230 | 
            +
                      raise NoMethodError.new(%(undefined method `#{ m }' for "#{ @string }":#{ self.class }))
         | 
| 231 | 
            +
                    end
         | 
| 224 232 | 
             
                  end
         | 
| 225 233 |  | 
| 226 234 | 
             
                  # Override Ruby's respond_to_missing? in order to support ::String interface
         | 
    
        data/lib/lotus/utils/version.rb
    CHANGED
    
    
    
        data/lotus-utils.gemspec
    CHANGED
    
    | @@ -6,8 +6,8 @@ require 'lotus/utils/version' | |
| 6 6 | 
             
            Gem::Specification.new do |spec|
         | 
| 7 7 | 
             
              spec.name          = 'lotus-utils'
         | 
| 8 8 | 
             
              spec.version       = Lotus::Utils::VERSION
         | 
| 9 | 
            -
              spec.authors       = ['Luca Guidi']
         | 
| 10 | 
            -
              spec.email         = ['me@lucaguidi.com']
         | 
| 9 | 
            +
              spec.authors       = ['Luca Guidi', 'Trung Lê']
         | 
| 10 | 
            +
              spec.email         = ['me@lucaguidi.com', 'trung.le@ruby-journal.com']
         | 
| 11 11 | 
             
              spec.description   = %q{Lotus utilities}
         | 
| 12 12 | 
             
              spec.summary       = %q{Ruby core extentions and Louts utilities}
         | 
| 13 13 | 
             
              spec.homepage      = 'http://lotusrb.org'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: lotus-utils
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Luca Guidi
         | 
| 8 | 
            +
            - Trung Lê
         | 
| 8 9 | 
             
            autorequire: 
         | 
| 9 10 | 
             
            bindir: bin
         | 
| 10 11 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 12 | 
            +
            date: 2015-01-08 00:00:00.000000000 Z
         | 
| 12 13 | 
             
            dependencies:
         | 
| 13 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 15 | 
             
              name: bundler
         | 
| @@ -55,6 +56,7 @@ dependencies: | |
| 55 56 | 
             
            description: Lotus utilities
         | 
| 56 57 | 
             
            email:
         | 
| 57 58 | 
             
            - me@lucaguidi.com
         | 
| 59 | 
            +
            - trung.le@ruby-journal.com
         | 
| 58 60 | 
             
            executables: []
         | 
| 59 61 | 
             
            extensions: []
         | 
| 60 62 | 
             
            extra_rdoc_files: []
         | 
| @@ -96,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 96 98 | 
             
                  version: '0'
         | 
| 97 99 | 
             
            requirements: []
         | 
| 98 100 | 
             
            rubyforge_project: 
         | 
| 99 | 
            -
            rubygems_version: 2. | 
| 101 | 
            +
            rubygems_version: 2.4.5
         | 
| 100 102 | 
             
            signing_key: 
         | 
| 101 103 | 
             
            specification_version: 4
         | 
| 102 104 | 
             
            summary: Ruby core extentions and Louts utilities
         |