Module: HoneyFormat

Includes:
Errors
Defined in:
lib/honey_format.rb,
lib/honey_format/csv.rb,
lib/honey_format/errors.rb,
lib/honey_format/cli/cli.rb,
lib/honey_format/version.rb,
lib/honey_format/registry.rb,
lib/honey_format/matrix/row.rb,
lib/honey_format/matrix/rows.rb,
lib/honey_format/configuration.rb,
lib/honey_format/matrix/header.rb,
lib/honey_format/matrix/matrix.rb,
lib/honey_format/helpers/helpers.rb,
lib/honey_format/cli/benchmark_cli.rb,
lib/honey_format/cli/result_writer.rb,
lib/honey_format/matrix/row_builder.rb,
lib/honey_format/converters/converters.rb,
lib/honey_format/converters/convert_number.rb,
lib/honey_format/converters/convert_string.rb,
lib/honey_format/converters/convert_boolean.rb,
lib/honey_format/converters/convert_date_and_time.rb,
lib/honey_format/converters/header_column_converter.rb

Overview

Main module for HoneyFormat

Defined Under Namespace

Modules: Converters, Errors, HeaderColumnConverter, Helpers Classes: BenchmarkCLI, CLI, CLIResultWriter, CSV, Configuration, Header, Matrix, Registry, Row, RowBuilder, Rows

Constant Summary collapse

HoneyCSV =

CSV alias

CSV
VERSION =

Gem version

[
  MAJOR_VERSION = 0,
  MINOR_VERSION = 27,
  PATCH_VERSION = 0,
].join('.')
ConvertNil =

Convert to nil

proc {}
ConvertDecimal =

Converts decimal or nil

proc do |v|
  begin
    Float(v)
  rescue ArgumentError, TypeError
    nil
  end
end
ConvertDecimalOrZero =

Converts to decimal or zero

proc { |v| v.to_f }
ConvertInteger =

Convert to integer or nil

proc do |v|
  begin
    Integer(v)
  rescue ArgumentError, TypeError
    nil
  end
end
ConvertIntegerOrZero =

Convert to integer or zero

proc { |v| v.to_i }
StrictConvertDecimal =

Convert to decimal or raise error

proc { |v| Float(v) }
StrictConvertInteger =

Convert to integer or raise error

proc { |v| Integer(v) }
ConvertDowncase =

Convert to downcase or nil

proc { |v| v&.downcase }
ConvertUpcase =

Convert to upcase or nil

proc { |v| v&.upcase }
ConvertStrip =

Convert to stripped string

proc { |v| v&.strip }
ConvertSymbol =

Convert to symbol or nil

proc { |v| v&.to_sym }
ConvertMD5 =

Convert to md5 or nil

proc { |v| Digest::MD5.hexdigest(v) if v }
ConvertHex =

Convert to hex or nil

proc { |v| SecureRandom.hex if v }
ConvertBlank =

Convert to blank string

proc { '' }
ConvertHeaderColumn =

Convert header column

HeaderColumnConverter
StrictConvertUpcase =

Convert to upcase or raise error

proc do |v|
  ConvertUpcase.call(v) || raise(ArgumentError, "can't convert nil to upcased string")
end
StrictConvertDowncase =

Convert to downcase or raise error

proc do |v|
  ConvertDowncase.call(v) || raise(ArgumentError, "can't convert nil to downcased string")
end
StrictConvertStrip =

Convert to downcase or raise error

proc do |v|
  ConvertStrip.call(v) || raise(ArgumentError, "can't convert nil to downcased string")
end
StrictConvertSymbol =

Convert to symbol or raise error

proc do |v|
  ConvertSymbol.call(v) || raise(ArgumentError, "can't convert nil to stripped string")
end
TRUTHY =

String values considered truthy

Set.new(%w[t T 1 y Y true TRUE] + [true]).freeze
FALSY =

String values considered falsy

Set.new(%w[f F 0 n N false FALSE] + [false]).freeze
ConvertBoolean =

Tries to convert value boolean to, returns nil if it can’t convert

proc do |v|
  if TRUTHY.include?(v)
    true
  elsif FALSY.include?(v)
    false
  end
end
StrictConvertBoolean =

Convert to boolean or raise error

proc do |v|
  ConvertBoolean.call(v).tap do |value|
    raise(ArgumentError, "can't convert #{v} to boolean") if value.nil?
  end
end
ConvertDate =

Convert to date

proc do |v|
  begin
    StrictConvertDate.call(v)
  rescue ArgumentError, TypeError
    nil
  end
end
ConvertDatetime =

Convert to datetime

proc do |v|
  begin
    StrictConvertDatetime.call(v)
  rescue ArgumentError, TypeError
    nil
  end
end
StrictConvertDate =

Convert to date or raise error

proc { |v| v.is_a?(Date) ? v : Date.parse(v) }
StrictConvertDatetime =

Convert to datetime or raise error

proc { |v| v.is_a?(Time) ? v : Time.parse(v) }

Class Method Summary collapse

Class Method Details

.configConfiguration

Returns the current configuration

Returns:



27
28
29
# File 'lib/honey_format.rb', line 27

def self.config
  configure
end

.configure {|configuration| ... } ⇒ Configuration

Configure HoneyFormat

Yields:

  • (configuration)

    the configuration

Yield Parameters:

Returns:



19
20
21
22
23
# File 'lib/honey_format.rb', line 19

def self.configure
  @configuration ||= Configuration.new
  yield(@configuration) if block_given?
  @configuration
end

.converter_registryRegistry

Returns the configured converter registry

Returns:

  • (Registry)

    the current converter registry



39
40
41
# File 'lib/honey_format.rb', line 39

def self.converter_registry
  config.converter_registry
end

.header_converter#call

Returns the configured header converter

Returns:

  • (#call)

    the current header converter



33
34
35
# File 'lib/honey_format.rb', line 33

def self.header_converter
  config.header_converter
end

.header_deduplicator_registryRegistry

Returns the configured deduplicator registry

Returns:

  • (Registry)

    the current deduplicator registry



45
46
47
# File 'lib/honey_format.rb', line 45

def self.header_deduplicator_registry
  config.header_deduplicator_registry
end