Skip to content

Commit

Permalink
Merge branch 'release/v0.1.5'
Browse files Browse the repository at this point in the history
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
  • Loading branch information
melriffe committed Sep 29, 2014
2 parents 104a2af + 3b3eabd commit 5bdf68c
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 10 deletions.
27 changes: 27 additions & 0 deletions LICENSE.txt
Expand Up @@ -20,3 +20,30 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------------------------------
----------------------------------------

Some portions of blank.rb are verbatim copies of software
licensed under the MIT license. That license is included below:

Copyright (c) 2005-2008 David Heinemeier Hansson

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 0 additions & 2 deletions flat.gemspec
Expand Up @@ -28,8 +28,6 @@ Gem::Specification.new do |spec|
"wiki" => "https://github.com/juicyparts/flat/wiki",
}

spec.add_runtime_dependency "extlib", "~> 0.9.0"

spec.add_development_dependency "bundler", ">= 1.6.2" # was "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rdoc", ">= 3.12" # was "~> 4.1.0"
Expand Down
89 changes: 89 additions & 0 deletions lib/extlib/blank.rb
@@ -0,0 +1,89 @@
class Object
##
# Returns true if the object is nil or empty (if applicable)
#
# [].blank? #=> true
# [1].blank? #=> false
# [nil].blank? #=> false
#
# @return [TrueClass, FalseClass]
#
# @api public
def blank?
nil? || (respond_to?(:empty?) && empty?)
end
end # class Object

class Numeric
##
# Numerics are never blank
#
# 0.blank? #=> false
# 1.blank? #=> false
# 6.54321.blank? #=> false
#
# @return [FalseClass]
#
# @api public
def blank?
false
end
end # class Numeric

class NilClass
##
# Nil is always blank
#
# nil.blank? #=> true
#
# @return [TrueClass]
#
# @api public
def blank?
true
end
end # class NilClass

class TrueClass
##
# True is never blank.
#
# true.blank? #=> false
#
# @return [FalseClass]
#
# @api public
def blank?
false
end
end # class TrueClass

class FalseClass
##
# False is always blank.
#
# false.blank? #=> true
#
# @return [TrueClass]
#
# @api public
def blank?
true
end
end # class FalseClass

class String
##
# Strips out whitespace then tests if the string is empty.
#
# "".blank? #=> true
# " ".blank? #=> true
# " hey ho ".blank? #=> false
#
# @return [TrueClass, FalseClass]
#
# @api public
def blank?
strip.empty?
end
end # class String
4 changes: 2 additions & 2 deletions lib/flat.rb
@@ -1,8 +1,8 @@
require 'extlib'
require 'extlib/blank'

require 'flat/version'
require 'flat/file'

module Flat #:nodoc
include Extlib

end
4 changes: 2 additions & 2 deletions lib/flat/errors.rb
Expand Up @@ -20,13 +20,13 @@ class RecordLengthError < FlatFileError; end

# = ShortRecordError
#
# The incoming line was shorter than expections defined.
# The incoming line was shorter than the defined width.
#
class ShortRecordError < RecordLengthError; end

# = LongRecordError
#
# The incoming line was longer than expections defined.
# The incoming line was longer than the defined width.
#
class LongRecordError < RecordLengthError; end

Expand Down
13 changes: 11 additions & 2 deletions lib/flat/field.rb
Expand Up @@ -36,7 +36,7 @@ def add_field name = nil, options = {}, &block

yield field_def if block_given?

pack_format << "A#{field_def.width}"
pack_format << field_def.pack_format
self.width += field_def.width

# TODO: Add a check here to ensure the Field has a name specified; it can be a String or Symbol
Expand Down Expand Up @@ -85,7 +85,8 @@ def self.included receiver #:nodoc:
# end
#
class Definition #:nodoc:
attr_accessor :parent, :name, :width, :padding, :aggressive
attr_reader :parent
attr_accessor :name, :width
attr_accessor :filters, :formatters, :map_in_proc

##
Expand Down Expand Up @@ -120,6 +121,14 @@ def aggressive?
@aggressive
end

#
# TODO: Find out what's capable with this pack foramat;
# String#pack, String#unpack
#
def pack_format
"A#{width}"
end

##
# Add a filter. Filters are used for processing field data when a flat file is
# being processed. For fomratting the data when writing a flat file, see
Expand Down
2 changes: 1 addition & 1 deletion lib/flat/version.rb
@@ -1,3 +1,3 @@
module Flat #:nodoc:
VERSION = "0.1.4"
VERSION = "0.1.5"
end
1 change: 1 addition & 0 deletions spec/lib/flat/field_spec.rb
Expand Up @@ -13,6 +13,7 @@
expect( field.parent ).to eq( flat_file )
expect( field.name ).to eq( :name )
expect( field.width ).to eq( 5 )
expect( field.pack_format ).to eq( 'A5' )
expect( field.padding? ).to be false
expect( field.aggressive? ).to be false
expect( field.filters ).to be_empty
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/flat_spec.rb
Expand Up @@ -5,7 +5,7 @@

describe 'Version' do
it 'should verify current gem version' do
expect(Flat::VERSION).to eq('0.1.4')
expect(Flat::VERSION).to eq('0.1.5')
end
end

Expand Down

0 comments on commit 5bdf68c

Please sign in to comment.