Skip to content

Commit

Permalink
extract supports_encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
infused committed Aug 15, 2015
1 parent ce21dad commit 38232cf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/dbf/column/base.rb
Expand Up @@ -127,12 +127,10 @@ def boolean(value) # nodoc

def encode_string(value, strip_output = false) # nodoc
output =
if @encoding && table.supports_encoding?
if table.supports_string_encoding?
value.to_s.force_encoding(@encoding).encode(*encoding_args)
elsif table.supports_iconv?
Iconv.conv('UTF-8', @encoding, value.to_s)
end
if supports_encoding? && table.supports_string_encoding?
value.to_s.force_encoding(@encoding).encode(*encoding_args)
elsif supports_encoding? && table.supports_iconv?
Iconv.conv('UTF-8', @encoding, value.to_s)
else
value
end
Expand Down Expand Up @@ -183,6 +181,10 @@ def validate_length
def validate_name
raise NameError, 'column name cannot be empty' if @name.empty?
end

def supports_encoding?
@encoding && table.supports_encoding?
end
end
end
end

0 comments on commit 38232cf

Please sign in to comment.