Class: EacRubyUtils::CustomFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/custom_format.rb

Overview

A formatter like [String.sprintf].

Defined Under Namespace

Classes: String

Constant Summary collapse

TYPE_PATTERN =
/[a-zA-Z]/.freeze
SEQUENCE_PATTERN =
/(?<!%)%(#{TYPE_PATTERN})/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapping) ⇒ CustomFormat

Returns a new instance of CustomFormat.



11
12
13
# File 'lib/eac_ruby_utils/custom_format.rb', line 11

def initialize(mapping)
  @mapping = mapping.transform_keys(&:to_sym).freeze
end

Instance Attribute Details

#mappingObject (readonly)

Returns the value of attribute mapping.



9
10
11
# File 'lib/eac_ruby_utils/custom_format.rb', line 9

def mapping
  @mapping
end

Instance Method Details

#format(string) ⇒ Object



15
16
17
# File 'lib/eac_ruby_utils/custom_format.rb', line 15

def format(string)
  ::EacRubyUtils::CustomFormat::String.new(self, string)
end